huggingface / api-inference-community

Apache License 2.0
163 stars 61 forks source link

Flair: Add support for PoS Tagging Models & Version Update #440

Closed stefan-it closed 2 months ago

stefan-it commented 3 months ago

Hi all,

Flair team here 😄

This PR adds support for PoS Tagging models and is fixing this reported bug.

Additionally, the Flair version is bumped to our latest 0.14.0 release.

Tests

I locally tested this PR. With the flair/ner-english NER model:

$ python3 manage.py start --task token-classification --framework flair "flair/ner-english"
$ curl -s -X POST -d "George Washington went to Washington." http://localhost:8000 | jq
[
  {
    "entity_group": "PER",
    "word": "George Washington",
    "start": 0,
    "end": 17,
    "score": 0.998886227607727
  },
  {
    "entity_group": "LOC",
    "word": "Washington",
    "start": 26,
    "end": 36,
    "score": 0.9942097663879395
  }
]

The PoS Tagging model flair/upos-english is now working:

$ python3 manage.py start --task token-classification --framework flair "flair/upos-english"
$ curl -s -X POST -d "Ich liebe Berlin, as they say" http://localhost:8000 | jq
[
  {
    "entity_group": "INTJ",
    "word": "Ich",
    "start": 0,
    "end": 3,
    "score": 0.5181307792663574
  },
  {
    "entity_group": "PUNCT",
    "word": "liebe",
    "start": 4,
    "end": 9,
    "score": 0.94031822681427
  },
  {
    "entity_group": "PROPN",
    "word": "Berlin",
    "start": 10,
    "end": 16,
    "score": 0.7861781120300293
  },
  {
    "entity_group": "ADV",
    "word": ",",
    "start": 16,
    "end": 17,
    "score": 0.4596414566040039
  },
  {
    "entity_group": "ADV",
    "word": "as",
    "start": 18,
    "end": 20,
    "score": 0.7350289821624756
  },
  {
    "entity_group": "PRON",
    "word": "they",
    "start": 21,
    "end": 25,
    "score": 0.8404370546340942
  },
  {
    "entity_group": "VERB",
    "word": "say",
    "start": 26,
    "end": 29,
    "score": 0.9999231100082397
  }
]