You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+58-28
Original file line number
Diff line number
Diff line change
@@ -12,17 +12,17 @@ A very simple framework for **state-of-the-art NLP**. Developed by [Humboldt Uni
12
12
Flair is:
13
13
14
14
***A powerful NLP library.** Flair allows you to apply our state-of-the-art natural language processing (NLP)
15
-
models to your text, such as named entity recognition (NER), part-of-speech tagging (PoS),
15
+
models to your text, such as named entity recognition (NER), sentiment analysis, part-of-speech tagging (PoS),
16
16
special support for [biomedical data](/resources/docs/HUNFLAIR.md),
17
17
sense disambiguation and classification, with support for a rapidly growing number of languages.
18
18
19
19
***A text embedding library.** Flair has simple interfaces that allow you to use and combine different word and
20
-
document embeddings, including our proposed **[Flair embeddings](https://www.aclweb.org/anthology/C18-1139/)**, BERT embeddings and ELMo embeddings.
20
+
document embeddings, including our proposed [Flair embeddings](https://www.aclweb.org/anthology/C18-1139/)and various transformers.
21
21
22
22
***A PyTorch NLP framework.** Our framework builds directly on [PyTorch](https://pytorch.org/), making it easy to
23
23
train your own models and experiment with new approaches using Flair embeddings and classes.
24
24
25
-
Now at [version 0.11](https://github.com/flairNLP/flair/releases)!
25
+
Now at [version 0.12](https://github.com/flairNLP/flair/releases)!
26
26
27
27
28
28
## State-of-the-Art Models
@@ -37,7 +37,7 @@ Flair ships with state-of-the-art models for a range of NLP tasks. For instance,
37
37
| Dutch | Conll-03 (4-class) |**95.25**|*93.7 [(Yu et al., 2020)](https://www.aclweb.org/anthology/2020.acl-main.577.pdf)*|[Flair Dutch 4-class NER demo](https://huggingface.co/flair/ner-dutch-large)|
38
38
| Spanish | Conll-03 (4-class) |**90.54**|*90.3 [(Yu et al., 2020)](https://www.aclweb.org/anthology/2020.acl-main.577.pdf)*|[Flair Spanish 4-class NER demo](https://huggingface.co/flair/ner-spanish-large)|
39
39
40
-
**New:** Most Flair sequence tagging models (named entity recognition, part-of-speech tagging etc.) are now hosted
40
+
Many Flair sequence tagging models (named entity recognition, part-of-speech tagging etc.) are also hosted
41
41
on the [__🤗 HuggingFace model hub__](https://huggingface.co/models?library=flair&sort=downloads)! You can browse models, check detailed information on how they were trained, and even try each model out online!
42
42
43
43
@@ -53,61 +53,91 @@ pip install flair
53
53
54
54
Flair requires Python 3.7+.
55
55
56
-
### Example Usage
56
+
### Example 1: Tag Entities in Text
57
57
58
-
Let's run named entity recognition (NER) over an example sentence. All you need to do is make a `Sentence`, load
58
+
Let's run **named entity recognition** (NER) over an example sentence. All you need to do is make a `Sentence`, load
59
59
a pre-trained model and use it to predict tags for the sentence:
60
60
61
61
```python
62
62
from flair.data import Sentence
63
-
from flair.modelsimportSequenceTagger
63
+
from flair.nnimportClassifier
64
64
65
65
# make a sentence
66
66
sentence = Sentence('I love Berlin .')
67
67
68
68
# load the NER tagger
69
-
tagger =SequenceTagger.load('ner')
69
+
tagger =Classifier.load('ner')
70
70
71
71
# run NER over sentence
72
72
tagger.predict(sentence)
73
+
74
+
# print the sentence with all annotations
75
+
print(sentence)
76
+
```
77
+
78
+
This should print:
79
+
80
+
```console
81
+
Sentence: "I love Berlin ." → ["Berlin"/LOC]
73
82
```
74
83
75
-
Done! The `Sentence` now has entity annotations. Print the sentence to see what the tagger found.
84
+
This means that "Berlin" was tagged as a **location entity** in this sentence.
85
+
86
+
**to learn more about NER tagging in Flair, check out our [NER tutorial](/resources/docs/TUTORIAL_TAGGING_NER.md)!*
87
+
88
+
89
+
### Example 2: Detect Sentiment
90
+
91
+
Let's run **sentiment analysis** over an example sentence to determine whether it is POSITIVE or NEGATIVE.
92
+
Same code as above, just a different model:
76
93
77
94
```python
78
-
# print the sentence with all annotations
79
-
print(sentence)
95
+
from flair.data import Sentence
96
+
from flair.nn import Classifier
97
+
98
+
# make a sentence
99
+
sentence = Sentence('I love Berlin .')
100
+
101
+
# load the NER tagger
102
+
tagger = Classifier.load('sentiment')
80
103
81
-
print('The following NER tags are found:')
104
+
# run NER over sentence
105
+
tagger.predict(sentence)
82
106
83
-
# iterate over entities and print each
84
-
for entity in sentence.get_spans('ner'):
85
-
print(entity)
107
+
# print the sentence with all annotations
108
+
print(sentence)
86
109
```
87
110
88
111
This should print:
89
112
90
113
```console
91
-
Sentence: "I love Berlin ." → ["Berlin"/LOC]
114
+
Sentence[4]: "I love Berlin ." → POSITIVE (0.9983)
115
+
```
92
116
93
-
The following NER tags are found:
117
+
This means that the sentence "I love Berlin" was tagged as having **POSITIVE** sentiment.
94
118
95
-
Span[2:3]: "Berlin" → LOC (0.999)
96
-
```
119
+
**to learn more about sentiment analysis in Flair, check out our [sentiment analysis tutorial](/resources/docs/TUTORIAL_TAGGING_SENTIMENT.md)!*
97
120
98
121
## Tutorials
99
122
100
123
We provide a set of **quick tutorials** to get you started with the library:
0 commit comments