Update README.md
Browse files
README.md
CHANGED
@@ -55,6 +55,7 @@ Users should verify the information provided by the model with up-to-date and pe
|
|
55 |
|
56 |
```python
|
57 |
|
|
|
58 |
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
59 |
from accelerate import Accelerator
|
60 |
|
@@ -85,12 +86,15 @@ def ask_question(question_type, question):
|
|
85 |
|
86 |
### Answer:
|
87 |
"""
|
88 |
-
#
|
89 |
-
|
90 |
-
|
|
|
91 |
return answer.strip()
|
92 |
|
|
|
93 |
# Example usage
|
94 |
question_type = "prevention"
|
95 |
question = "How can I protect myself from poisoning caused by marine toxins?"
|
96 |
print(ask_question(question_type, question))
|
|
|
|
55 |
|
56 |
```python
|
57 |
|
58 |
+
|
59 |
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
60 |
from accelerate import Accelerator
|
61 |
|
|
|
86 |
|
87 |
### Answer:
|
88 |
"""
|
89 |
+
# Adjust max_length and specify eos_token_id for better stopping
|
90 |
+
eos_token_id = tokenizer.eos_token_id
|
91 |
+
response = generator(prompt, max_length=1024, eos_token_id=eos_token_id, num_return_sequences=1)
|
92 |
+
answer = response[0]['generated_text'][len(prompt):]
|
93 |
return answer.strip()
|
94 |
|
95 |
+
|
96 |
# Example usage
|
97 |
question_type = "prevention"
|
98 |
question = "How can I protect myself from poisoning caused by marine toxins?"
|
99 |
print(ask_question(question_type, question))
|
100 |
+
|