Spaces:
Build error
Build error
danseith
commited on
Commit
·
fce4c33
1
Parent(s):
3566540
Added TempScalePipe back in
Browse files
app.py
CHANGED
@@ -4,26 +4,29 @@ from transformers import pipeline, Pipeline
|
|
4 |
|
5 |
unmasker = pipeline("fill-mask", model="anferico/bert-for-patents")
|
6 |
|
7 |
-
example = 'A crustless
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
|
|
|
|
|
|
27 |
|
28 |
def unmask(text):
|
29 |
# text = add_mask(text)
|
|
|
4 |
|
5 |
unmasker = pipeline("fill-mask", model="anferico/bert-for-patents")
|
6 |
|
7 |
+
example = 'A crustless [MASK] made from two slices of baked bread'
|
8 |
+
|
9 |
+
|
10 |
+
def add_mask(text, size=1):
|
11 |
+
split_text = text.split()
|
12 |
+
idx = np.random.randint(len(split_text), size=size)
|
13 |
+
for i in idx:
|
14 |
+
split_text[i] = '[MASK]'
|
15 |
+
return ' '.join(split_text)
|
16 |
+
|
17 |
+
|
18 |
+
class TempScalePipe(Pipeline):
|
19 |
+
def _forward(self, model_inputs):
|
20 |
+
outputs = self.model(**model_inputs)
|
21 |
+
return outputs
|
22 |
+
|
23 |
+
def postprocess(self, model_outputs, temp=1e3):
|
24 |
+
out = model_outputs["logits"] / temp
|
25 |
+
best_class = out.softmax(-1)
|
26 |
+
print(out)
|
27 |
+
probas = np.random.multinomial(1, best_class, 1)
|
28 |
+
return np.argmax(probas)
|
29 |
+
|
30 |
|
31 |
def unmask(text):
|
32 |
# text = add_mask(text)
|