Commit
·
a76743d
1
Parent(s):
207aa3b
Improve README
Browse files
README.md
CHANGED
@@ -44,6 +44,65 @@ It could be useful for:
|
|
44 |
- Query preprocessing
|
45 |
- Low-latency query expansion
|
46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
## Citation
|
48 |
|
49 |
If you find my work helpful, feel free to give me a citation.
|
|
|
44 |
- Query preprocessing
|
45 |
- Low-latency query expansion
|
46 |
|
47 |
+
## Usage
|
48 |
+
|
49 |
+
```python
|
50 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
51 |
+
from unsloth import FastLanguageModel
|
52 |
+
|
53 |
+
# Model configuration
|
54 |
+
MODEL_NAME = "s-emanuilov/query-expansion-Qwen2.5-3B"
|
55 |
+
MAX_SEQ_LENGTH = 2048
|
56 |
+
DTYPE = "float16"
|
57 |
+
LOAD_IN_4BIT = True
|
58 |
+
|
59 |
+
# Load model and tokenizer
|
60 |
+
model, tokenizer = FastLanguageModel.from_pretrained(
|
61 |
+
model_name=MODEL_NAME,
|
62 |
+
max_seq_length=MAX_SEQ_LENGTH,
|
63 |
+
dtype=DTYPE,
|
64 |
+
load_in_4bit=LOAD_IN_4BIT,
|
65 |
+
)
|
66 |
+
|
67 |
+
# Enable faster inference
|
68 |
+
FastLanguageModel.for_inference(model)
|
69 |
+
|
70 |
+
# Define prompt template
|
71 |
+
PROMPT_TEMPLATE = """Below is a search query. Generate relevant expansions and related terms that would help broaden and enhance the search results.
|
72 |
+
|
73 |
+
### Query:
|
74 |
+
{query}
|
75 |
+
|
76 |
+
### Expansions:
|
77 |
+
{output}"""
|
78 |
+
|
79 |
+
# Prepare input
|
80 |
+
query = "apple stock"
|
81 |
+
inputs = tokenizer(
|
82 |
+
[PROMPT_TEMPLATE.format(query=query, output="")],
|
83 |
+
return_tensors="pt"
|
84 |
+
).to("cuda")
|
85 |
+
|
86 |
+
# Generate with streaming output
|
87 |
+
from transformers import TextStreamer
|
88 |
+
streamer = TextStreamer(tokenizer)
|
89 |
+
output = model.generate(
|
90 |
+
**inputs,
|
91 |
+
streamer=streamer,
|
92 |
+
max_new_tokens=128,
|
93 |
+
)
|
94 |
+
```
|
95 |
+
|
96 |
+
## Example
|
97 |
+
|
98 |
+
**Input**: "apple stock "
|
99 |
+
**Expansions**:
|
100 |
+
- "apple stock price"
|
101 |
+
- "how to invest in apple stocks"
|
102 |
+
- "apple stock analysis"
|
103 |
+
- "what is the future of apple stocks?"
|
104 |
+
- "understanding apple's stock market performance"
|
105 |
+
|
106 |
## Citation
|
107 |
|
108 |
If you find my work helpful, feel free to give me a citation.
|