nkasmanoff commited on
Commit
6ad2c3c
1 Parent(s): 77d8b8e

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +42 -0
README.md CHANGED
@@ -27,6 +27,48 @@ Basically, this model is meant to be a means of allowing very small LLMs (i.e. 8
27
 
28
  All limitations and biases are inherited from the parent model.
29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  ### Framework versions
31
 
32
  - Transformers 4.41.1
 
27
 
28
  All limitations and biases are inherited from the parent model.
29
 
30
+ ### Example Usage
31
+
32
+ from transformers import AutoTokenizer
33
+ from transformers import AutoModelForSequenceClassification
34
+
35
+ key_tools = ['take_picture', 'no_tool_needed',
36
+ 'check_news', 'check_weather', 'play_spotify']
37
+
38
+
39
+ def get_id2tool_name(id, key_tools):
40
+ return key_tools[id]
41
+
42
+
43
+ def remove_any_non_alphanumeric_characters(text):
44
+ return ''.join(e for e in text if e.isalnum() or e.isspace())
45
+
46
+
47
+ def load_model():
48
+ tokenizer = AutoTokenizer.from_pretrained("google-bert/bert-base-uncased")
49
+ model = AutoModelForSequenceClassification.from_pretrained(
50
+ "nkasmanoff/tool-bert")
51
+
52
+ model.eval()
53
+ return model, tokenizer
54
+
55
+
56
+ def predict_tool(question, model, tokenizer):
57
+ question = remove_any_non_alphanumeric_characters(question)
58
+ inputs = tokenizer(question, return_tensors="pt")
59
+
60
+ outputs = model(**inputs)
61
+
62
+ logits = outputs.logits
63
+ return get_id2tool_name(logits.argmax().item(), key_tools)
64
+
65
+ model, tokenizer = load_model()
66
+
67
+ question = "What's the weather outside?"
68
+
69
+ predict_tool(question, model, tokenizer)
70
+ > check_weather
71
+
72
  ### Framework versions
73
 
74
  - Transformers 4.41.1