ehdwns1516 commited on
Commit
affa4b0
1 Parent(s): a650c23

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +58 -0
README.md ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # ehdwns1516/bert-base-uncased_SWAG
2
+
3
+ * This model has been trained as a [SWAG dataset](https://huggingface.co/ehdwns1516/bert-base-uncased_SWAG).
4
+
5
+ Sentence Inference Multiple Choice DEMO: [Ainize DEMO](https://main-sentence-inference-multiple-choice-ehdwns1516.endpoint.ainize.ai/)
6
+
7
+ Sentence Inference Multiple Choice API: [Ainize API](https://ainize.web.app/redirect?git_repo=https://github.com/ehdwns1516/sentence_inference_multiple_choice)
8
+
9
+ ## Overview
10
+
11
+ Language model: [bert-base-uncased](https://huggingface.co/bert-base-uncased)
12
+
13
+ Language: English
14
+
15
+ Training data: [SWAG dataset](https://huggingface.co/datasets/swag)
16
+
17
+ Code: See [Ainize Workspace](https://ainize.ai/workspace/create?imageId=hnj95592adzr02xPTqss&git=https://github.com/ehdwns1516/Multiple_choice_SWAG_finetunning)
18
+
19
+ ## Usage
20
+ ## In Transformers
21
+
22
+ ```
23
+ from transformers import AutoTokenizer, AutoModelForMultipleChoice
24
+
25
+ tokenizer = AutoTokenizer.from_pretrained("ehdwns1516/bert-base-uncased_SWAG")
26
+
27
+ model = AutoModelForMultipleChoice.from_pretrained("ehdwns1516/bert-base-uncased_SWAG")
28
+
29
+ def run_model(candicates_count, context: str, candicates: list[str]):
30
+ assert len(candicates) == candicates_count, "you need " + candicates_count + " candidates"
31
+ choices_inputs = []
32
+ for c in candicates:
33
+ text_a = "" # empty context
34
+ text_b = context + " " + c
35
+ inputs = tokenizer(
36
+ text_a,
37
+ text_b,
38
+ add_special_tokens=True,
39
+ max_length=128,
40
+ padding="max_length",
41
+ truncation=True,
42
+ return_overflowing_tokens=True,
43
+ )
44
+ choices_inputs.append(inputs)
45
+
46
+ input_ids = torch.LongTensor([x["input_ids"] for x in choices_inputs])
47
+ output = model(input_ids=input_ids)
48
+
49
+ return {"result": candicates[torch.argmax(output.logits).item()]}
50
+
51
+ items = list()
52
+ count = 4 //candicates count
53
+ context = "your context"
54
+ for i in range(int(count)):
55
+ items.append("sentence")
56
+
57
+ result = run_model(count, context, items)
58
+ ```