mohamedemam
commited on
Update README.md
Browse files
README.md
CHANGED
@@ -70,11 +70,79 @@ Text generation
|
|
70 |
### Training Data
|
71 |
- **mohamedemam/Essay-quetions-auto-grading-arabic**
|
72 |
|
73 |
-
[More Information Needed]
|
74 |
|
75 |
### Training Procedure
|
76 |
|
77 |
using Trl
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
### Chat Format Function
|
79 |
This function formats the input context, question, and answer into a specific structure for the model to process.
|
80 |
|
|
|
70 |
### Training Data
|
71 |
- **mohamedemam/Essay-quetions-auto-grading-arabic**
|
72 |
|
|
|
73 |
|
74 |
### Training Procedure
|
75 |
|
76 |
using Trl
|
77 |
+
### Pipline
|
78 |
+
```python
|
79 |
+
from transformers import Pipeline
|
80 |
+
import torch.nn.functional as F
|
81 |
+
|
82 |
+
|
83 |
+
class MyPipeline:
|
84 |
+
|
85 |
+
def __init__(self,model,tokenizer):
|
86 |
+
self.model=model
|
87 |
+
self.tokenizer=tokenizer
|
88 |
+
|
89 |
+
def chat_Format(self,context, quetion, answer):
|
90 |
+
return "Instruction:/n check answer is true or false of next quetion using context below:\n" + "#context: " + context + f".\n#quetion: " + quetion + f".\n#student answer: " + answer + ".\n#response: "
|
91 |
+
|
92 |
+
|
93 |
+
def __call__(self, context, quetion, answer,generate=1,max_new_tokens=4, num_beams=2, do_sample=False,num_return_sequences=1):
|
94 |
+
inp=self.chat_Format(context, quetion, answer)
|
95 |
+
w = self.tokenizer(inp, add_special_tokens=True,
|
96 |
+
pad_to_max_length=True,
|
97 |
+
return_attention_mask=True,
|
98 |
+
return_tensors='pt')
|
99 |
+
response=""
|
100 |
+
if(generate):
|
101 |
+
outputs = self.tokenizer.batch_decode(self.model.generate(input_ids=w['input_ids'].cuda(), attention_mask=w['attention_mask'].cuda(), max_new_tokens=max_new_tokens, num_beams=num_beams, do_sample=do_sample, num_return_sequences=num_return_sequences), skip_special_tokens=True)
|
102 |
+
response = outputs
|
103 |
+
|
104 |
+
s =self.model(input_ids=w['input_ids'].cuda(), attention_mask=w['attention_mask'].cuda())['logits'][0][-1]
|
105 |
+
s = F.softmax(s, dim=-1)
|
106 |
+
yes_token_id = self.tokenizer.convert_tokens_to_ids(self.tokenizer.tokenize("True")[0])
|
107 |
+
no_token_id = self.tokenizer.convert_tokens_to_ids(self.tokenizer.tokenize("False")[0])
|
108 |
+
|
109 |
+
for i in ["Yes", "yes", "True", "true","صحيح"]:
|
110 |
+
for word in self.tokenizer.tokenize(i):
|
111 |
+
s[yes_token_id] += s[self.tokenizer.convert_tokens_to_ids(word)]
|
112 |
+
for i in ["No", "no", "False", "false","خطأ"]:
|
113 |
+
for word in self.tokenizer.tokenize(i):
|
114 |
+
|
115 |
+
s[no_token_id] += s[self.tokenizer.convert_tokens_to_ids(word)]
|
116 |
+
true = (s[yes_token_id] / (s[no_token_id] + s[yes_token_id])).item()
|
117 |
+
return {"response": response, "true": true}
|
118 |
+
context="""Large language models, such as GPT-4, are trained on vast amounts of text data to understand and generate human-like text. The deployment of these models involves several steps:
|
119 |
+
|
120 |
+
Model Selection: Choosing a pre-trained model that fits the application's needs.
|
121 |
+
Infrastructure Setup: Setting up the necessary hardware and software infrastructure to run the model efficiently, including cloud services, GPUs, and necessary libraries.
|
122 |
+
Integration: Integrating the model into an application, which can involve setting up APIs or embedding the model directly into the software.
|
123 |
+
Optimization: Fine-tuning the model for specific tasks or domains and optimizing it for performance and cost-efficiency.
|
124 |
+
Monitoring and Maintenance: Ensuring the model performs well over time, monitoring for biases, and updating the model as needed."""
|
125 |
+
quetion="What are the key considerations when choosing a cloud service provider for deploying a large language model like GPT-4?"
|
126 |
+
answer="""When choosing a cloud service provider for deploying a large language model like GPT-4, the key considerations include:
|
127 |
+
Compute Power: Ensure the provider offers high-performance GPUs or TPUs capable of handling the computational requirements of the model.
|
128 |
+
Scalability: The ability to scale resources up or down based on the application's demand to handle varying workloads efficiently.
|
129 |
+
Cost: Analyze the pricing models to understand the costs associated with compute time, storage, data transfer, and any other services.
|
130 |
+
Integration and Support: Availability of tools and libraries that support easy integration of the model into your applications, along with robust technical support and documentation.
|
131 |
+
Security and Compliance: Ensure the provider adheres to industry standards for security and compliance, protecting sensitive data and maintaining privacy.
|
132 |
+
Latency and Availability: Consider the geographical distribution of data centers to ensure low latency and high availability for your end-users.
|
133 |
+
|
134 |
+
By evaluating these factors, you can select a cloud service provider that aligns with your deployment needs, ensuring efficient and cost-effective operation of your large language model."""
|
135 |
+
from peft import PeftModel, PeftConfig
|
136 |
+
from transformers import AutoModelForCausalLM
|
137 |
+
|
138 |
+
config = PeftConfig.from_pretrained("mohamedemam/Em2-llama-7b")
|
139 |
+
base_model = AutoModelForCausalLM.from_pretrained("NousResearch/Llama-2-7b-hf")
|
140 |
+
model = PeftModel.from_pretrained(base_model, "mohamedemam/Em2-llama-7b")
|
141 |
+
pipe=MyPipeline(model,tokenizer)
|
142 |
+
print(pipe(context,quetion,answer,generate=True,max_new_tokens=4, num_beams=2, do_sample=False,num_return_sequences=1))
|
143 |
+
```
|
144 |
+
- **output:**{'response': ["Instruction:/n check answer is true or false of next quetion using context below:\n#context: Large language models, such as GPT-4, are trained on vast amounts of text data to understand and generate human-like text. The deployment of these models involves several steps:\n\n Model Selection: Choosing a pre-trained model that fits the application's needs.\n Infrastructure Setup: Setting up the necessary hardware and software infrastructure to run the model efficiently, including cloud services, GPUs, and necessary libraries.\n Integration: Integrating the model into an application, which can involve setting up APIs or embedding the model directly into the software.\n Optimization: Fine-tuning the model for specific tasks or domains and optimizing it for performance and cost-efficiency.\n Monitoring and Maintenance: Ensuring the model performs well over time, monitoring for biases, and updating the model as needed..\n#quetion: What are the key considerations when choosing a cloud service provider for deploying a large language model like GPT-4?.\n#student answer: When choosing a cloud service provider for deploying a large language model like GPT-4, the key considerations include:\n Compute Power: Ensure the provider offers high-performance GPUs or TPUs capable of handling the computational requirements of the model.\n Scalability: The ability to scale resources up or down based on the application's demand to handle varying workloads efficiently.\n Cost: Analyze the pricing models to understand the costs associated with compute time, storage, data transfer, and any other services.\n Integration and Support: Availability of tools and libraries that support easy integration of the model into your applications, along with robust technical support and documentation.\n Security and Compliance: Ensure the provider adheres to industry standards for security and compliance, protecting sensitive data and maintaining privacy.\n Latency and Availability: Consider the geographical distribution of data centers to ensure low latency and high availability for your end-users.\n\nBy evaluating these factors, you can select a cloud service provider that aligns with your deployment needs, ensuring efficient and cost-effective operation of your large language model..\n#response: true the answer is"], 'true': 0.943033754825592}
|
145 |
+
|
146 |
### Chat Format Function
|
147 |
This function formats the input context, question, and answer into a specific structure for the model to process.
|
148 |
|