Fill-Mask
Transformers
Safetensors
bert
masked-language-modeling
historical-nlp
temporal-language-model
Instructions to use TextMachineProject/NewsBERT_1800-1920-Temporal with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use TextMachineProject/NewsBERT_1800-1920-Temporal with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("fill-mask", model="TextMachineProject/NewsBERT_1800-1920-Temporal")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForMaskedLM tokenizer = AutoTokenizer.from_pretrained("TextMachineProject/NewsBERT_1800-1920-Temporal") model = AutoModelForMaskedLM.from_pretrained("TextMachineProject/NewsBERT_1800-1920-Temporal", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Update README.md
Browse files
README.md
CHANGED
|
@@ -76,9 +76,7 @@ from continuous_time_embedding import load_continuous_time_model
|
|
| 76 |
tokenizer, model = load_continuous_time_model(REPO_ID)
|
| 77 |
device = next(model.parameters()).device
|
| 78 |
```
|
| 79 |
-
|
| 80 |
-
### Check changes in top mask prediction or in token probability
|
| 81 |
-
|
| 82 |
|
| 83 |
```python
|
| 84 |
def predict_masked(sentence, year, top_k=5):
|
|
@@ -121,7 +119,11 @@ def get_target_word_probability(sentence, target_word, year):
|
|
| 121 |
|
| 122 |
prob = math.exp(logprob_sum) if len(target_ids) == 1 else None
|
| 123 |
return prob, logprob_sum
|
|
|
|
| 124 |
|
|
|
|
|
|
|
|
|
|
| 125 |
### Example 1: fill-mask, top predictions at different years
|
| 126 |
sentence = "The [MASK] arrived on time."
|
| 127 |
for year in [1800, 1810, 1820, 1830, 1840, 1850, 1860, 1870, 1880, 1890, 1900, 1910, 1920]:
|
|
|
|
| 76 |
tokenizer, model = load_continuous_time_model(REPO_ID)
|
| 77 |
device = next(model.parameters()).device
|
| 78 |
```
|
| 79 |
+
### Basic functions to get top mask predictions and token probability
|
|
|
|
|
|
|
| 80 |
|
| 81 |
```python
|
| 82 |
def predict_masked(sentence, year, top_k=5):
|
|
|
|
| 119 |
|
| 120 |
prob = math.exp(logprob_sum) if len(target_ids) == 1 else None
|
| 121 |
return prob, logprob_sum
|
| 122 |
+
```
|
| 123 |
|
| 124 |
+
### Check changes in top mask prediction or in token probability
|
| 125 |
+
|
| 126 |
+
```python
|
| 127 |
### Example 1: fill-mask, top predictions at different years
|
| 128 |
sentence = "The [MASK] arrived on time."
|
| 129 |
for year in [1800, 1810, 1820, 1830, 1840, 1850, 1860, 1870, 1880, 1890, 1900, 1910, 1920]:
|