Update README.md
Browse files
README.md
CHANGED
@@ -10,10 +10,9 @@ license: apache-2.0
|
|
10 |
|
11 |
slim-sentiment has been fine-tuned for **sentiment analysis** function calls, with output of JSON dictionary corresponding to specific named entity keys.
|
12 |
|
13 |
-
Each slim model has a corresponding 'tool' in a separate repository, e.g., 'slim-sentiment-tool', which a 4-bit quantized gguf version of the model that is intended to be used for inference.
|
14 |
-
|
15 |
-
|
16 |
|
|
|
17 |
|
18 |
### Model Description
|
19 |
|
@@ -48,31 +47,61 @@ All of the SLIM models use a novel prompt instruction structured as follows:
|
|
48 |
|
49 |
The fastest way to get started with BLING is through direct import in transformers:
|
50 |
|
51 |
-
|
52 |
-
|
53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
|
|
|
55 |
|
56 |
-
|
|
|
57 |
|
58 |
-
|
|
|
|
|
|
|
|
|
59 |
|
60 |
-
|
|
|
|
|
|
|
|
|
|
|
61 |
|
62 |
-
|
63 |
-
|
64 |
|
65 |
-
To get the best results, package "my_prompt" as follows:
|
66 |
|
67 |
-
|
68 |
|
|
|
69 |
|
|
|
|
|
|
|
70 |
|
|
|
|
|
|
|
71 |
## Model Card Contact
|
72 |
|
73 |
Darren Oberst & llmware team
|
74 |
|
75 |
-
Please reach out anytime if you are interested in this project and would like to participate and work with us!
|
76 |
-
|
77 |
|
78 |
|
|
|
10 |
|
11 |
slim-sentiment has been fine-tuned for **sentiment analysis** function calls, with output of JSON dictionary corresponding to specific named entity keys.
|
12 |
|
13 |
+
Each slim model has a corresponding 'tool' in a separate repository, e.g., [**'slim-sentiment-tool'**](www.huggingface.co/llmware/slim-sentiment-tool/), which a 4-bit quantized gguf version of the model that is intended to be used for inference.
|
|
|
|
|
14 |
|
15 |
+
Inference speed and loading time is much faster with the 'tool' versions of the model.
|
16 |
|
17 |
### Model Description
|
18 |
|
|
|
47 |
|
48 |
The fastest way to get started with BLING is through direct import in transformers:
|
49 |
|
50 |
+
import ast
|
51 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
52 |
+
|
53 |
+
model = AutoModelForCausalLM.from_pretrained("llmware/slim-sentiment")
|
54 |
+
tokenizer = AutoTokenizer.from_pretrained("llmware/slim-sentiment")
|
55 |
+
|
56 |
+
text = "The markets declined for a second straight days on news of disappointing earnings."
|
57 |
+
|
58 |
+
keys = "sentiment"
|
59 |
+
|
60 |
+
prompt = "<human>: " + text + "\n" + "<classify> " + keys + "</classify>" + "\n<bot>: "
|
61 |
+
|
62 |
+
# huggingface standard generation script
|
63 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
64 |
+
start_of_output = len(inputs.input_ids[0])
|
65 |
+
|
66 |
+
outputs = model.generate(inputs.input_ids.to('cpu'), eos_token_id=tokenizer.eos_token_id,
|
67 |
+
pad_token_id=tokenizer.eos_token_id, do_sample=True, temperature=0.3, max_new_tokens=100)
|
68 |
|
69 |
+
output_only = tokenizer.decode(outputs[0][start_of_output:], skip_special_tokens=True)
|
70 |
|
71 |
+
print("input text sample - ", text)
|
72 |
+
print("llm_response - ", output_only)
|
73 |
|
74 |
+
# where it gets interesting
|
75 |
+
try:
|
76 |
+
# convert llm response output from string to json
|
77 |
+
output_only = ast.literal_eval(output_only)
|
78 |
+
print("converted to json automatically")
|
79 |
|
80 |
+
# look for the key passed in the prompt as a dictionary entry
|
81 |
+
if keys in output_only:
|
82 |
+
if "negative" in output_only[keys]:
|
83 |
+
print("sentiment appears negative - need to handle ...")
|
84 |
+
else:
|
85 |
+
print("response does not appear to include the designated key - will need to try again.")
|
86 |
|
87 |
+
except:
|
88 |
+
print("could not convert to json automatically - ", output_only)
|
89 |
|
|
|
90 |
|
91 |
+
## Using as Function Call in LLMWare
|
92 |
|
93 |
+
We envision the slim models deployed in a pipeline/workflow/templating framework that handles the prompt packaging more elegantly. Check out llmware for one such implementation:
|
94 |
|
95 |
+
from llmware.models import ModelCatalog
|
96 |
+
slim_model = ModelCatalog().load_model("llmware/slim-sentiment")
|
97 |
+
response = slim_model.function_call(text,params=["sentiment"], function="classify")
|
98 |
|
99 |
+
print("llmware - llm_response: ", response)
|
100 |
+
|
101 |
+
|
102 |
## Model Card Contact
|
103 |
|
104 |
Darren Oberst & llmware team
|
105 |
|
|
|
|
|
106 |
|
107 |
|