Update README.md
Browse files
README.md
CHANGED
@@ -22,4 +22,48 @@ datasets:
|
|
22 |
|
23 |
This llama model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library.
|
24 |
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
This llama model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library.
|
24 |
|
25 |
+
## Example usage:
|
26 |
+
|
27 |
+
Install dependencies. Check [Unsloth documentation](https://github.com/unslothai/unsloth) for specific installation for other environments.
|
28 |
+
|
29 |
+
````python
|
30 |
+
%%capture
|
31 |
+
# Installs Unsloth, Xformers (Flash Attention) and all other packages!
|
32 |
+
!pip install "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
|
33 |
+
!pip install --no-deps "xformers<0.0.26" trl peft accelerate bitsandbytes
|
34 |
+
````
|
35 |
+
|
36 |
+
Then you can load the model and use it as inference
|
37 |
+
|
38 |
+
```python
|
39 |
+
from unsloth.chat_templates import get_chat_template
|
40 |
+
|
41 |
+
tokenizer = get_chat_template(
|
42 |
+
tokenizer,
|
43 |
+
chat_template = "llama-3",
|
44 |
+
map_eos_token = True,
|
45 |
+
)
|
46 |
+
|
47 |
+
FastLanguageModel.for_inference(model) # Enable native 2x faster inference
|
48 |
+
|
49 |
+
schema = """Node properties: - **Question** - `favorites`: INTEGER Example: "0" - `answered`: BOOLEAN - `text`: STRING Example: "### This is: Bug ### Specifications OS: Win10" - `link`: STRING Example: "https://stackoverflow.com/questions/62224586/playg" - `createdAt`: DATE_TIME Min: 2020-06-05T16:57:19Z, Max: 2020-06-05T21:49:16Z - `title`: STRING Example: "Playground is not loading with apollo-server-lambd" - `id`: INTEGER Min: 62220505, Max: 62224586 - `upVotes`: INTEGER Example: "0" - `score`: INTEGER Example: "-1" - `downVotes`: INTEGER Example: "1" - **Tag** - `name`: STRING Example: "aws-lambda" - **User** - `image`: STRING Example: "https://lh3.googleusercontent.com/-NcFYSuXU0nk/AAA" - `link`: STRING Example: "https://stackoverflow.com/users/10251021/alexandre" - `id`: INTEGER Min: 751, Max: 13681006 - `reputation`: INTEGER Min: 1, Max: 420137 - `display_name`: STRING Example: "Alexandre Le" Relationship properties: The relationships: (:Question)-[:TAGGED]->(:Tag) (:User)-[:ASKED]->(:Question)"""
|
50 |
+
question = "Identify the top 5 questions with the most downVotes."
|
51 |
+
|
52 |
+
messages = [
|
53 |
+
{"role": "system", "content": "Given an input question, convert it to a Cypher query. No pre-amble."},
|
54 |
+
{"role": "user", "content": f"""Based on the Neo4j graph schema below, write a Cypher query that would answer the user's question:
|
55 |
+
{schema}
|
56 |
+
|
57 |
+
Question: {question}
|
58 |
+
Cypher query:"""}
|
59 |
+
]
|
60 |
+
inputs = tokenizer.apply_chat_template(
|
61 |
+
messages,
|
62 |
+
tokenize = True,
|
63 |
+
add_generation_prompt = True, # Must add for generation
|
64 |
+
return_tensors = "pt",
|
65 |
+
).to("cuda")
|
66 |
+
|
67 |
+
outputs = model.generate(input_ids = inputs, max_new_tokens = 128, use_cache = True)
|
68 |
+
tokenizer.batch_decode(outputs)
|
69 |
+
```
|