Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InferenceApi for TokenClassification does not work #344

Closed
KoichiYasuoka opened this issue Sep 11, 2021 · 5 comments
Closed

InferenceApi for TokenClassification does not work #344

KoichiYasuoka opened this issue Sep 11, 2021 · 5 comments

Comments

@KoichiYasuoka
Copy link

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?

@julien-c
Copy link
Member

cc'ing @Narsil for visibility

@KoichiYasuoka
Copy link
Author

KoichiYasuoka commented Sep 13, 2021

Thank you @julien-c for your cc with @Narsil, and I've just found a very big PR huggingface/transformers#13308 and a smaller PR huggingface/transformers#13493

@Narsil
Copy link
Contributor

Narsil commented Sep 13, 2021

Ok, it's fixed now.

It seemed linked to recursive import, which is odd, we're looking into it.

@KoichiYasuoka
Copy link
Author

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.

@Narsil
Copy link
Contributor

Narsil commented 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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants