turingmachine
commited on
Commit
•
44ea4f1
1
Parent(s):
90fb457
Data card
Browse files
README.md
ADDED
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
language:
|
3 |
+
- en
|
4 |
+
thumbnail: "url to a thumbnail used in social sharing"
|
5 |
+
tags:
|
6 |
+
- hupd
|
7 |
+
- roberta
|
8 |
+
- distilroberta
|
9 |
+
- patents
|
10 |
+
license: cc-by-sa-4.0
|
11 |
+
datasets:
|
12 |
+
- HUPD/hupd
|
13 |
+
---
|
14 |
+
|
15 |
+
# HUPD DistilRoBERTA-Base Model
|
16 |
+
|
17 |
+
This HUPD DistilRoBERTa model was fine-tuned on the HUPD dataset with a masked language modeling objective. It was originally introduced in [this paper](TBD).
|
18 |
+
|
19 |
+
For more information about the Harvard USPTO Patent Dataset, please feel free to visit the [project website](https://patentdataset.org/) or the [project's GitHub repository](https://github.com/suzgunmirac/hupd).
|
20 |
+
|
21 |
+
|
22 |
+
### How to Use
|
23 |
+
|
24 |
+
You can use this model directly with a pipeline for masked language modeling:
|
25 |
+
|
26 |
+
```python
|
27 |
+
from transformers import pipeline
|
28 |
+
model = pipeline(task="fill-mask", model="turingmachine/hupd-distilroberta-base")
|
29 |
+
model("Improved <mask> for playing a game of thumb wrestling.")
|
30 |
+
```
|
31 |
+
|
32 |
+
Here is the output:
|
33 |
+
```python
|
34 |
+
[{'score': 0.4274042248725891,
|
35 |
+
'sequence': 'Improved method for playing a game of thumb wrestling.',
|
36 |
+
'token': 5448,
|
37 |
+
'token_str': ' method'},
|
38 |
+
{'score': 0.06967400759458542,
|
39 |
+
'sequence': 'Improved system for playing a game of thumb wrestling.',
|
40 |
+
'token': 467,
|
41 |
+
'token_str': ' system'},
|
42 |
+
{'score': 0.06849079579114914,
|
43 |
+
'sequence': 'Improved device for playing a game of thumb wrestling.',
|
44 |
+
'token': 2187,
|
45 |
+
'token_str': ' device'},
|
46 |
+
{'score': 0.04544765502214432,
|
47 |
+
'sequence': 'Improved apparatus for playing a game of thumb wrestling.',
|
48 |
+
'token': 26529,
|
49 |
+
'token_str': ' apparatus'},
|
50 |
+
{'score': 0.025765646249055862,
|
51 |
+
'sequence': 'Improved means for playing a game of thumb wrestling.',
|
52 |
+
'token': 839,
|
53 |
+
'token_str': ' means'}]
|
54 |
+
```
|
55 |
+
|
56 |
+
Alternatively, you can load the model and use it as follows:
|
57 |
+
|
58 |
+
```python
|
59 |
+
import torch
|
60 |
+
from transformers import AutoTokenizer, AutoModelForMaskedLM
|
61 |
+
|
62 |
+
# cuda/cpu
|
63 |
+
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
64 |
+
|
65 |
+
tokenizer = AutoTokenizer.from_pretrained("turingmachine/hupd-distilroberta-base")
|
66 |
+
model = AutoModelForMaskedLM.from_pretrained("turingmachine/hupd-distilroberta-base").to(device)
|
67 |
+
|
68 |
+
TEXT = "Improved <mask> for playing a game of thumb wrestling."
|
69 |
+
|
70 |
+
inputs = tokenizer(TEXT, return_tensors="pt").to(device)
|
71 |
+
|
72 |
+
with torch.no_grad():
|
73 |
+
logits = model(**inputs).logits
|
74 |
+
|
75 |
+
# retrieve indices of <mask>
|
76 |
+
mask_token_indxs = (inputs.input_ids == tokenizer.mask_token_id)[0].nonzero(as_tuple=True)[0]
|
77 |
+
|
78 |
+
for mask_idx in mask_token_indxs:
|
79 |
+
predicted_token_id = logits[0, mask_idx].argmax(axis=-1)
|
80 |
+
output = tokenizer.decode(predicted_token_id)
|
81 |
+
print(f'Prediction for the <mask> token at index {mask_idx}: "{output}"')
|
82 |
+
```
|
83 |
+
Here is the output:
|
84 |
+
```python
|
85 |
+
Prediction for the <mask> token at index 2: " method"
|
86 |
+
```
|
87 |
+
|
88 |
+
## Citation
|
89 |
+
|
90 |
+
For more information, please take a look at the original paper.
|
91 |
+
|
92 |
+
* Paper: [The Harvard USPTO Patent Dataset: A Large-Scale, Well-Structured, and Multi-Purpose Corpus of Patent Applications](TBD)
|
93 |
+
|
94 |
+
* Authors: *Mirac Suzgun, Luke Melas-Kyriazi, Suproteem K. Sarkar, Scott Duke Kominers, and Stuart M. Shieber*
|
95 |
+
|
96 |
+
* BibTeX:
|
97 |
+
```
|
98 |
+
@article{suzgun2022hupd,
|
99 |
+
title={The Harvard USPTO Patent Dataset: A Large-Scale, Well-Structured, and Multi-Purpose Corpus of Patent Applications},
|
100 |
+
author={Suzgun, Mirac and Melas-Kyriazi, Luke and Sarkar, Suproteem K and Kominers, Scott and Shieber, Stuart},
|
101 |
+
year={2022}
|
102 |
+
}
|
103 |
+
```
|