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

_convert_id_to_tokens for XLNet not working #945

Closed
chris-boson opened this issue Aug 1, 2019 · 3 comments
Closed

_convert_id_to_tokens for XLNet not working #945

chris-boson opened this issue Aug 1, 2019 · 3 comments
Labels

Comments

@chris-boson
Copy link

chris-boson commented Aug 1, 2019

text = self.tokenizer.convert_ids_to_tokens(token_list)
  File "/home/lambda/repos/pytorch-transformers/pytorch_transformers/tokenization_utils.py", line 444, in convert_ids_to_tokens
    tokens.append(self._convert_id_to_token(index))
  File "/home/lambda/repos/pytorch-transformers/pytorch_transformers/tokenization_xlnet.py", line 170, in _convert_id_to_token
    token = self.sp_model.IdToPiece(index)
  File "/home/lambda/python-envs/research/lib/python3.6/site-packages/sentencepiece.py", line 187, in IdToPiece
    return _sentencepiece.SentencePieceProcessor_IdToPiece(self, id)
TypeError: in method 'SentencePieceProcessor_IdToPiece', argument 2 of type 'int'

I find that if I explicitly convert ids to integers it works fine. In tokenization_xlnet.py

def _convert_id_to_token(self, index, return_unicode=True):
    """Converts an index (integer) in a token (string/unicode) using the vocab."""
    token = self.sp_model.IdToPiece(int(index))
    if six.PY2 and return_unicode and isinstance(token, str):
        token = token.decode('utf-8')
    return token
@thomwolf
Copy link
Member

thomwolf commented Aug 5, 2019

Which command can we use to reproduce the behavior?

@chris-boson
Copy link
Author

Upon further testing, looks like this tokenizer doesn't like numpy arrays, the other ones seem to be fine

import numpy as np
from pytorch_transformers import XLNetTokenizer, TransfoXLTokenizer, BertTokenizer

tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')
print(tokenizer.convert_ids_to_tokens(np.array([3, 4, 6, 2356])))
tokenizer = TransfoXLTokenizer.from_pretrained('transfo-xl-wt103')
print(tokenizer.convert_ids_to_tokens(np.array([3, 4, 6, 2356])))
tokenizer = XLNetTokenizer.from_pretrained('xlnet-base-cased')
print(tokenizer.convert_ids_to_tokens(np.array([3, 4, 6, 2356]).tolist()))
print(tokenizer.convert_ids_to_tokens(np.array([3, 4, 6, 2356]))) # Above error

@stale
Copy link

stale bot commented Oct 4, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

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

No branches or pull requests

2 participants