Add usage example
Browse files
README.md
CHANGED
|
@@ -31,6 +31,72 @@ SwissBERT contains the following language adapters:
|
|
| 31 |
## License
|
| 32 |
Attribution-NonCommercial 4.0 International (CC BY-NC 4.0).
|
| 33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
## Bias, Risks, and Limitations
|
| 35 |
- SwissBERT is mainly intended for tagging tokens in written text (e.g., named entity recognition, part-of-speech tagging), text classification, and the encoding of words, sentences or documents into fixed-size embeddings.
|
| 36 |
SwissBERT is not designed for generating text.
|
|
|
|
| 31 |
## License
|
| 32 |
Attribution-NonCommercial 4.0 International (CC BY-NC 4.0).
|
| 33 |
|
| 34 |
+
## Usage (masked language modeling)
|
| 35 |
+
|
| 36 |
+
```python
|
| 37 |
+
from transformers import pipeline
|
| 38 |
+
|
| 39 |
+
fill_mask = pipeline(model="ZurichNLP/swissbert")
|
| 40 |
+
```
|
| 41 |
+
|
| 42 |
+
### German example
|
| 43 |
+
```python
|
| 44 |
+
fill_mask.model.set_default_language("de_CH")
|
| 45 |
+
fill_mask("Der schönste Kanton der Schweiz ist <mask>.")
|
| 46 |
+
```
|
| 47 |
+
Output:
|
| 48 |
+
```
|
| 49 |
+
[{'score': 0.1373230218887329,
|
| 50 |
+
'token': 331,
|
| 51 |
+
'token_str': 'Zürich',
|
| 52 |
+
'sequence': 'Der schönste Kanton der Schweiz ist Zürich.'},
|
| 53 |
+
{'score': 0.08464793860912323,
|
| 54 |
+
'token': 5903,
|
| 55 |
+
'token_str': 'Appenzell',
|
| 56 |
+
'sequence': 'Der schönste Kanton der Schweiz ist Appenzell.'},
|
| 57 |
+
{'score': 0.08250337839126587,
|
| 58 |
+
'token': 10800,
|
| 59 |
+
'token_str': 'Graubünden',
|
| 60 |
+
'sequence': 'Der schönste Kanton der Schweiz ist Graubünden.'},
|
| 61 |
+
{'score': 0.07495423406362534,
|
| 62 |
+
'token': 4833,
|
| 63 |
+
'token_str': 'Schwyz',
|
| 64 |
+
'sequence': 'Der schönste Kanton der Schweiz ist Schwyz.'},
|
| 65 |
+
{'score': 0.07253701984882355,
|
| 66 |
+
'token': 3734,
|
| 67 |
+
'token_str': 'Uri',
|
| 68 |
+
'sequence': 'Der schönste Kanton der Schweiz ist Uri.'}]
|
| 69 |
+
```
|
| 70 |
+
|
| 71 |
+
### French example
|
| 72 |
+
```python
|
| 73 |
+
fill_mask.model.set_default_language("fr_CH")
|
| 74 |
+
fill_mask("Je m'appelle <mask> Federer.")
|
| 75 |
+
```
|
| 76 |
+
Output:
|
| 77 |
+
```
|
| 78 |
+
[{'score': 0.9943694472312927,
|
| 79 |
+
'token': 1371,
|
| 80 |
+
'token_str': 'Roger',
|
| 81 |
+
'sequence': "Je m'appelle Roger Federer."},
|
| 82 |
+
{'score': 0.00029945766436867416,
|
| 83 |
+
'token': 689,
|
| 84 |
+
'token_str': 'donc',
|
| 85 |
+
'sequence': "Je m'appelle donc Federer."},
|
| 86 |
+
{'score': 0.00022272868955042213,
|
| 87 |
+
'token': 71,
|
| 88 |
+
'token_str': 'r',
|
| 89 |
+
'sequence': "Je m'appeller Federer."},
|
| 90 |
+
{'score': 0.00020624867465812713,
|
| 91 |
+
'token': 10739,
|
| 92 |
+
'token_str': 'Robin',
|
| 93 |
+
'sequence': "Je m'appelle Robin Federer."},
|
| 94 |
+
{'score': 0.00016592108295299113,
|
| 95 |
+
'token': 15523,
|
| 96 |
+
'token_str': 'Bâlois',
|
| 97 |
+
'sequence': "Je m'appelle Bâlois Federer."}]
|
| 98 |
+
```
|
| 99 |
+
|
| 100 |
## Bias, Risks, and Limitations
|
| 101 |
- SwissBERT is mainly intended for tagging tokens in written text (e.g., named entity recognition, part-of-speech tagging), text classification, and the encoding of words, sentences or documents into fixed-size embeddings.
|
| 102 |
SwissBERT is not designed for generating text.
|