hf-tuner commited on
Commit
5c73593
verified
1 Parent(s): c8bb4a5

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +66 -18
README.md CHANGED
@@ -1,21 +1,21 @@
1
- ---
2
- library_name: transformers
3
- license: mit
4
- base_model: microsoft/MiniLM-L12-H384-uncased
5
- tags:
6
- - generated_from_trainer
7
- - extractive_QA
8
- model-index:
9
- - name: bert-mini-squadv2
10
- results: []
11
- datasets:
12
- - hf-tuner/squad_v2.0.1
13
- language:
14
- - en
15
- metrics:
16
- - exact_match
17
- pipeline_tag: question-answering
18
- ---
19
 
20
  <!-- This model card has been generated automatically according to the information the Trainer had access to. You
21
  should probably proofread and complete it, then remove this comment. -->
@@ -31,6 +31,54 @@ It achieves the following results on the evaluation set:
31
 
32
  MiniLMv1-L12-H384-uncased: 12-layer, 384-hidden, 12-heads, 33M parameters, 2.7x faster than BERT-Base
33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  ### Training hyperparameters
35
 
36
  The following hyperparameters were used during training:
 
1
+ ---
2
+ library_name: transformers
3
+ license: mit
4
+ base_model: microsoft/MiniLM-L12-H384-uncased
5
+ tags:
6
+ - generated_from_trainer
7
+ - extractive_QA
8
+ model-index:
9
+ - name: bert-mini-squadv2
10
+ results: []
11
+ datasets:
12
+ - hf-tuner/squad_v2.0.1
13
+ language:
14
+ - en
15
+ metrics:
16
+ - exact_match
17
+ pipeline_tag: question-answering
18
+ ---
19
 
20
  <!-- This model card has been generated automatically according to the information the Trainer had access to. You
21
  should probably proofread and complete it, then remove this comment. -->
 
31
 
32
  MiniLMv1-L12-H384-uncased: 12-layer, 384-hidden, 12-heads, 33M parameters, 2.7x faster than BERT-Base
33
 
34
+ ## How to use
35
+
36
+ ```python
37
+ import torch
38
+ from transformers import BertForQuestionAnswering, AutoTokenizer
39
+
40
+ model_id='hf-tuner/bert-mini-squadv2'
41
+ device = 'cuda' if torch.cuda.is_available() else 'cpu'
42
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
43
+ bert_qa = BertForQuestionAnswering.from_pretrained(model_id).to(device)
44
+ bert_qa = bert_qa.half()
45
+
46
+ def get_answers(ctxq):
47
+ inputs = tokenizer(ctxq, padding=True, return_tensors='pt')
48
+ for k,v in inputs.items():
49
+ inputs[k] = v.to(device)
50
+
51
+ with torch.no_grad():
52
+ outputs = bert_qa(**inputs)
53
+
54
+ start_idxs = outputs.start_logits.argmax(dim=-1)
55
+ end_idxs = outputs.end_logits.argmax(dim=-1)
56
+
57
+ predictions = []
58
+ for i, (start_idx, end_idx) in enumerate(zip(start_idxs, end_idxs)):
59
+ if start_idx == end_idx:
60
+ predictions.append("<no_answer>")
61
+ else:
62
+ predict_answer_tokens = inputs['input_ids'][i, start_idx : end_idx]
63
+ pred_answer = tokenizer.decode(predict_answer_tokens)
64
+ predictions.append(pred_answer)
65
+ return predictions
66
+
67
+
68
+ context = """In Q3 2024, xAI raised $6 billion in a Series C round led by Valor Equity Partners and Andreessen Horowitz, with participation from Sequoia Capital, Fidelity, and Saudi Arabia鈥檚 Kingdom Holding Company, bringing its post-money valuation to $50 billion.
69
+ """
70
+ question_1 = "Which two investors co-led xAI鈥檚 $6 billion Series C round announced in Q3 2024?"
71
+ question_2 = "On what exact date in Q3 2024 was xAI鈥檚 $6 billion Series C funding round officially closed?"
72
+
73
+ get_answers([
74
+ [context, question_1],
75
+ [context, question_2],
76
+ ])
77
+
78
+ >>> ['valor equity partners and andreessen horowitz', '<no_answer>']
79
+
80
+ ```
81
+
82
  ### Training hyperparameters
83
 
84
  The following hyperparameters were used during training: