question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

InferenceApi for TokenClassification does not work

See original GitHub issue

I’ve tried InferenceApi for the pipeline of token-classification but failed:

>>> from huggingface_hub.inference_api import InferenceApi
>>> api=InferenceApi("KoichiYasuoka/bert-base-japanese-upos")
>>> r=api(inputs="國境の長いトンネルを拔けると雪國であつた。")
>>> import json
>>> print(json.dumps(r,indent=2,ensure_ascii=False))
{
  "error": "maximum recursion depth exceeded while calling a Python object"
}

I remember that it worked last month and the result still remains in the cache:

>>> from huggingface_hub.inference_api import InferenceApi
>>> api=InferenceApi("KoichiYasuoka/bert-base-japanese-upos")
>>> r=api(inputs="難儀な難儀は難儀する")
>>> import json
>>> print(json.dumps(r,indent=2,ensure_ascii=False))
[
  {
    "entity_group": "ADJ",
    "score": 0.6918697953224182,
    "word": "難 儀",
    "start": null,
    "end": null
  },
  {
    "entity_group": "AUX",
    "score": 0.995212972164154,
    "word": "な",
    "start": null,
    "end": null
  },
  {
    "entity_group": "NOUN",
    "score": 0.9972944259643555,
    "word": "難 儀",
    "start": null,
    "end": null
  },
  {
    "entity_group": "ADP",
    "score": 0.9995647072792053,
    "word": "は",
    "start": null,
    "end": null
  },
  {
    "entity_group": "VERB",
    "score": 0.6875597238540649,
    "word": "難 儀",
    "start": null,
    "end": null
  },
  {
    "entity_group": "AUX",
    "score": 0.9953439235687256,
    "word": "す る",
    "start": null,
    "end": null
  }
]

Something changed on InferenceApi or TokenClassification?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Narsilcommented, Sep 13, 2021

Found the culprit which was linked to bad merge between master and the API fork (Turns out GPT2ForTokenClassification was added relatively recently).

0reactions
KoichiYasuokacommented, Sep 13, 2021

Thank you @Narsil and I’ve just confirmed that it works well:

>>> from huggingface_hub.inference_api import InferenceApi
>>> api=InferenceApi("KoichiYasuoka/bert-base-japanese-upos")
>>> r=api(inputs="國境の長いトンネルを拔けると雪國であつた。")
>>> import json
>>> print(json.dumps(r,indent=2,ensure_ascii=False))
[
  {
    "entity_group": "NOUN",
    "score": 0.9991488456726074,
    "word": "國境",
    "start": 0,
    "end": 2
  },
  {
    "entity_group": "ADP",
    "score": 0.99976646900177,
    "word": "の",
    "start": 2,
    "end": 3
  },
  {
    "entity_group": "ADJ",
    "score": 0.9954113960266113,
    "word": "長い",
    "start": 3,
    "end": 5
  },
  {
    "entity_group": "NOUN",
    "score": 0.9995394349098206,
    "word": "トンネル",
    "start": 5,
    "end": 9
  },
  {
    "entity_group": "ADP",
    "score": 0.9997807145118713,
    "word": "を",
    "start": 9,
    "end": 10
  },
  {
    "entity_group": "VERB",
    "score": 0.9993178844451904,
    "word": "拔ける",
    "start": 10,
    "end": 13
  },
  {
    "entity_group": "CCONJ",
    "score": 0.9845631718635559,
    "word": "と",
    "start": 13,
    "end": 14
  },
  {
    "entity_group": "NOUN",
    "score": 0.9390370845794678,
    "word": "雪國",
    "start": 14,
    "end": 16
  },
  {
    "entity_group": "AUX",
    "score": 0.9977393746376038,
    "word": "で",
    "start": 16,
    "end": 17
  },
  {
    "entity_group": "AUX",
    "score": 0.9874789118766785,
    "word": "あつた",
    "start": 17,
    "end": 20
  },
  {
    "entity_group": "PUNCT",
    "score": 0.9998145699501038,
    "word": "。",
    "start": 20,
    "end": 21
  }
]

Thank you again and I close this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Detailed parameters - Hugging Face
In general the Hosted API Inference accepts a simple string as an input. However, more advanced usage depends on the “task” that the...
Read more >
[inference] token classification | Kaggle
In essence, I treat it as a token classification problem instead of text classification. I insert in CLS tokens before each discourse text...
Read more >
notebooks/token_classification-tf.ipynb at main - GitHub
In this notebook, we will see how to fine-tune one of the Transformers model to a token classification task, which is the task...
Read more >
Infer trained model API | Elasticsearch Guide [8.5] | Elastic
none : No truncation occurs; the inference request receives an error. first : Only the first sequence is ... NER is a special...
Read more >
Named Entity Recognition - Sparse Use Cases - Neural Magic
You will apply a “named entity recognition” token classification use case ... of miscellaneous entities that do not belong to the previous three...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found