Upload README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,90 @@
|
|
1 |
---
|
2 |
-
license: apache-2.0
|
|
|
3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
+
license: apache-2.0
|
3 |
+
inference: false
|
4 |
---
|
5 |
+
|
6 |
+
# SLIM-TOPICS
|
7 |
+
|
8 |
+
<!-- Provide a quick summary of what the model is/does. -->
|
9 |
+
|
10 |
+
**slim-topics** is part of the SLIM ("**S**tructured **L**anguage **I**nstruction **M**odel") model series, consisting of small, specialized decoder-based models, fine-tuned for function-calling.
|
11 |
+
|
12 |
+
slim-sentiment has been fine-tuned for **topic analysis** function calls, generating output consisting of a python dictionary corresponding to specified keys, e.g.:
|
13 |
+
|
14 |
+
`{"topics": ["..."]}`
|
15 |
+
|
16 |
+
|
17 |
+
SLIM models are designed to generate structured outputs that can be used programmatically as part of a multi-step, multi-model LLM-based automation workflow.
|
18 |
+
|
19 |
+
Each slim model has a 'quantized tool' version, e.g., [**'slim-topics-tool'**](https://huggingface.co/llmware/slim-topics-tool).
|
20 |
+
|
21 |
+
|
22 |
+
## Prompt format:
|
23 |
+
|
24 |
+
`function = "classify"`
|
25 |
+
`params = "topics"`
|
26 |
+
`prompt = "<human> " + {text} + "\n" + `
|
27 |
+
`"<{function}> " + {params} + "</{function}>" + "\n<bot>:"`
|
28 |
+
|
29 |
+
|
30 |
+
<details>
|
31 |
+
<summary>Transformers Script </summary>
|
32 |
+
|
33 |
+
model = AutoModelForCausalLM.from_pretrained("llmware/slim-topics")
|
34 |
+
tokenizer = AutoTokenizer.from_pretrained("llmware/slim-topics")
|
35 |
+
|
36 |
+
function = "classify"
|
37 |
+
params = "topic"
|
38 |
+
|
39 |
+
text = "The stock market declined yesterday as investors worried increasingly about the slowing economy."
|
40 |
+
|
41 |
+
prompt = "<human>: " + text + "\n" + f"<{function}> {params} </{function}>\n<bot>:"
|
42 |
+
|
43 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
44 |
+
start_of_input = len(inputs.input_ids[0])
|
45 |
+
|
46 |
+
outputs = model.generate(
|
47 |
+
inputs.input_ids.to('cpu'),
|
48 |
+
eos_token_id=tokenizer.eos_token_id,
|
49 |
+
pad_token_id=tokenizer.eos_token_id,
|
50 |
+
do_sample=True,
|
51 |
+
temperature=0.3,
|
52 |
+
max_new_tokens=100
|
53 |
+
)
|
54 |
+
|
55 |
+
output_only = tokenizer.decode(outputs[0][start_of_input:], skip_special_tokens=True)
|
56 |
+
|
57 |
+
print("output only: ", output_only)
|
58 |
+
|
59 |
+
# here's the fun part
|
60 |
+
try:
|
61 |
+
output_only = ast.literal_eval(llm_string_output)
|
62 |
+
print("success - converted to python dictionary automatically")
|
63 |
+
except:
|
64 |
+
print("fail - could not convert to python dictionary automatically - ", llm_string_output)
|
65 |
+
|
66 |
+
</details>
|
67 |
+
|
68 |
+
<details>
|
69 |
+
|
70 |
+
|
71 |
+
|
72 |
+
|
73 |
+
<summary>Using as Function Call in LLMWare</summary>
|
74 |
+
|
75 |
+
from llmware.models import ModelCatalog
|
76 |
+
slim_model = ModelCatalog().load_model("llmware/slim-topics")
|
77 |
+
response = slim_model.function_call(text,params=["topics"], function="classify")
|
78 |
+
|
79 |
+
print("llmware - llm_response: ", response)
|
80 |
+
|
81 |
+
</details>
|
82 |
+
|
83 |
+
|
84 |
+
## Model Card Contact
|
85 |
+
|
86 |
+
Darren Oberst & llmware team
|
87 |
+
|
88 |
+
[Join us on Discord](https://discord.gg/MhZn5Nc39h)
|
89 |
+
|
90 |
+
|