Upload README.md
Browse files
README.md
CHANGED
@@ -1,81 +1,85 @@
|
|
1 |
---
|
2 |
-
license:
|
3 |
-
inference: false
|
4 |
---
|
5 |
|
6 |
-
#
|
7 |
|
8 |
<!-- Provide a quick summary of what the model is/does. -->
|
9 |
|
10 |
-
slim-
|
11 |
|
12 |
-
|
13 |
|
14 |
-
|
15 |
|
16 |
-
|
17 |
|
18 |
-
- **Developed by:** llmware
|
19 |
-
- **Model type:** Dragon
|
20 |
-
- **Language(s) (NLP):** English
|
21 |
-
- **License:** Apache 2.0
|
22 |
-
- **Finetuned from model:** Microsoft Phi-3
|
23 |
|
|
|
24 |
|
25 |
-
|
|
|
|
|
|
|
26 |
|
27 |
-
<!-- This section is meant to convey both technical and sociotechnical limitations. -->
|
28 |
|
29 |
-
|
|
|
30 |
|
|
|
|
|
31 |
|
32 |
-
|
|
|
33 |
|
34 |
-
|
|
|
|
|
35 |
|
36 |
-
|
37 |
-
|
38 |
-
model = AutoModelForCausalLM.from_pretrained("bling-phi-2-v0", trust_remote_code=True)
|
39 |
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
1. Text Passage Context, and
|
49 |
-
2. Specific question or instruction based on the text passage
|
50 |
-
|
51 |
-
To get the best results, package "my_prompt" as follows:
|
52 |
|
53 |
-
|
54 |
|
|
|
55 |
|
56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
|
58 |
-
# prepare prompt packaging used in fine-tuning process
|
59 |
-
new_prompt = "<human>: " + entries["context"] + "\n" + entries["query"] + "\n" + "<bot>:"
|
60 |
|
61 |
-
inputs = tokenizer(new_prompt, return_tensors="pt")
|
62 |
-
start_of_output = len(inputs.input_ids[0])
|
63 |
|
64 |
-
|
65 |
-
|
66 |
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
pad_token_id=tokenizer.eos_token_id,
|
71 |
-
do_sample=True,
|
72 |
-
temperature=0.3,
|
73 |
-
max_new_tokens=100,
|
74 |
-
)
|
75 |
|
76 |
-
|
77 |
|
|
|
78 |
|
|
|
79 |
## Model Card Contact
|
80 |
|
81 |
-
Darren Oberst & llmware team
|
|
|
|
|
|
1 |
---
|
2 |
+
license: cc-by-sa-4.0
|
3 |
+
inference: false
|
4 |
---
|
5 |
|
6 |
+
# SLIM-EXTRACT
|
7 |
|
8 |
<!-- Provide a quick summary of what the model is/does. -->
|
9 |
|
10 |
+
**slim-extract** implements a specialized function-calling customizable 'extract' capability that takes as an input a context passage, a customized key, and outputs a python dictionary with key that corresponds to the customized key, with a value consisting of a list of items extracted from the text corresponding to that key, e.g.,
|
11 |
|
12 |
+
`{'universities': ['Berkeley, Stanford, Yale, University of Florida, ...'] }`
|
13 |
|
14 |
+
This model is fine-tuned on top of [**llmware/bling-stable-lm-3b-4e1t-v0**](https://huggingface.co/llmware/bling-stable-lm-3b-4e1t-v0), which in turn, is a fine-tune of stabilityai/stablelm-3b-4elt.
|
15 |
|
16 |
+
For fast inference use, we would recommend the 'quantized tool' version, e.g., [**'slim-extract-tool'**](https://huggingface.co/llmware/slim-extract-tool).
|
17 |
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
+
## Prompt format:
|
20 |
|
21 |
+
`function = "extract"`
|
22 |
+
`params = "{custom key}"`
|
23 |
+
`prompt = "<human> " + {text} + "\n" + `
|
24 |
+
`"<{function}> " + {params} + "</{function}>" + "\n<bot>:"`
|
25 |
|
|
|
26 |
|
27 |
+
<details>
|
28 |
+
<summary>Transformers Script </summary>
|
29 |
|
30 |
+
model = AutoModelForCausalLM.from_pretrained("llmware/slim-extract")
|
31 |
+
tokenizer = AutoTokenizer.from_pretrained("llmware/slim-extract")
|
32 |
|
33 |
+
function = "extract"
|
34 |
+
params = "company"
|
35 |
|
36 |
+
text = "Tesla stock declined yesterday 8% in premarket trading after a poorly-received event in San Francisco yesterday, in which the company indicated a likely shortfall in revenue."
|
37 |
+
|
38 |
+
prompt = "<human>: " + text + "\n" + f"<{function}> {params} </{function}>\n<bot>:"
|
39 |
|
40 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
41 |
+
start_of_input = len(inputs.input_ids[0])
|
|
|
42 |
|
43 |
+
outputs = model.generate(
|
44 |
+
inputs.input_ids.to('cpu'),
|
45 |
+
eos_token_id=tokenizer.eos_token_id,
|
46 |
+
pad_token_id=tokenizer.eos_token_id,
|
47 |
+
do_sample=True,
|
48 |
+
temperature=0.3,
|
49 |
+
max_new_tokens=100
|
50 |
+
)
|
|
|
|
|
|
|
|
|
51 |
|
52 |
+
output_only = tokenizer.decode(outputs[0][start_of_input:], skip_special_tokens=True)
|
53 |
|
54 |
+
print("output only: ", output_only)
|
55 |
|
56 |
+
# here's the fun part
|
57 |
+
try:
|
58 |
+
output_only = ast.literal_eval(llm_string_output)
|
59 |
+
print("success - converted to python dictionary automatically")
|
60 |
+
except:
|
61 |
+
print("fail - could not convert to python dictionary automatically - ", llm_string_output)
|
62 |
+
|
63 |
+
</details>
|
64 |
+
|
65 |
+
<details>
|
66 |
|
|
|
|
|
67 |
|
|
|
|
|
68 |
|
69 |
+
|
70 |
+
<summary>Using as Function Call in LLMWare</summary>
|
71 |
|
72 |
+
from llmware.models import ModelCatalog
|
73 |
+
slim_model = ModelCatalog().load_model("llmware/slim-extract")
|
74 |
+
response = slim_model.function_call(text,params=["company"], function="extract")
|
|
|
|
|
|
|
|
|
|
|
75 |
|
76 |
+
print("llmware - llm_response: ", response)
|
77 |
|
78 |
+
</details>
|
79 |
|
80 |
+
|
81 |
## Model Card Contact
|
82 |
|
83 |
+
Darren Oberst & llmware team
|
84 |
+
|
85 |
+
[Join us on Discord](https://discord.gg/MhZn5Nc39h)
|