Update README.md
Browse files
README.md
CHANGED
@@ -20,62 +20,35 @@ tags:
|
|
20 |
## Usage:
|
21 |
|
22 |
```
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
do_sample=True,
|
50 |
-
temperature=temp)
|
51 |
-
|
52 |
-
# Generate text using the pipeline
|
53 |
-
pipe = pipeline(task="text-generation",
|
54 |
-
model=model,
|
55 |
-
tokenizer=tokenizer,
|
56 |
-
max_length=200)
|
57 |
-
result = pipe(f"<s>[INST] {prompt} [/INST]")
|
58 |
-
generated_text = result[0]['generated_text']
|
59 |
-
|
60 |
-
# Find the index of "### Assistant" in the generated text
|
61 |
-
index = generated_text.find("[/INST] ")
|
62 |
-
if index != -1:
|
63 |
-
# Extract the substring after "### Assistant"
|
64 |
-
substring_after_assistant = generated_text[index + len("[/INST] "):].strip()
|
65 |
-
else:
|
66 |
-
# If "### Assistant" is not found, use the entire generated text
|
67 |
-
substring_after_assistant = generated_text.strip()
|
68 |
-
|
69 |
-
if show_metrics:
|
70 |
-
# Calculate evaluation metrics
|
71 |
-
metrics = run_metrics(substring_after_assistant, prompt, model_id)
|
72 |
-
|
73 |
-
return substring_after_assistant, metrics
|
74 |
-
else:
|
75 |
-
return substring_after_assistant
|
76 |
|
|
|
77 |
|
78 |
-
|
79 |
-
|
80 |
-
print(generated_text)
|
81 |
```
|
|
|
20 |
## Usage:
|
21 |
|
22 |
```
|
23 |
+
from transformers import AutoTokenizer
|
24 |
+
import transformers
|
25 |
+
import torch
|
26 |
+
|
27 |
+
model = "aloobun/llama2-7b-openhermes-15k-mini"
|
28 |
+
prompt = "What are large language models?"
|
29 |
+
|
30 |
+
tokenizer = AutoTokenizer.from_pretrained(model)
|
31 |
+
pipeline = transformers.pipeline(
|
32 |
+
"text-generation",
|
33 |
+
model=model,
|
34 |
+
torch_dtype=torch.float16,
|
35 |
+
device_map="auto",
|
36 |
+
)
|
37 |
+
|
38 |
+
sequences = pipeline(
|
39 |
+
f'[INST] {prompt} [/INST]',
|
40 |
+
do_sample=True,
|
41 |
+
top_k=10,
|
42 |
+
num_return_sequences=1,
|
43 |
+
eos_token_id=tokenizer.eos_token_id,
|
44 |
+
max_length=200,
|
45 |
+
)
|
46 |
+
for seq in sequences:
|
47 |
+
print(f"Result: {seq['generated_text']}")
|
48 |
+
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
|
50 |
+
### Output:
|
51 |
|
52 |
+
```
|
53 |
+
Result: [INST] What are large language models? [/INST] Large language models are artificial intelligence systems that can be trained on vast amounts of text to generate human-like language. Libraries of natural language processing (NLP) algorithms like BERT and GPT have allowed these systems to learn and improve their capacity for language understanding and generation. These language models have found applications in natural language translation, text summarization, chatbots, and even creative writing. They can help in tasks like predicting the next word in a sentence or even generating a whole text based on a given topic or prompt. Large language models have the potential to revolutionize many industries, from customer support to content creation and beyond. However, their use and development raise important ethical and societal questions, such as the impact on employment or the potential misuse of generated content. As AI technology continues to advance, the role and capabilities of large language models will continue to evolve.
|
|
|
54 |
```
|