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

BERT tokenizerの逆斜線 #25

Closed
watanabe2362 opened this issue Sep 23, 2020 · 2 comments
Closed

BERT tokenizerの逆斜線 #25

watanabe2362 opened this issue Sep 23, 2020 · 2 comments

Comments

@watanabe2362
Copy link

watanabe2362 commented Sep 23, 2020

Windows10、AnacondaでBERTを使用していたら、fugashiに代わっているようで下記のエラーとなった。

from sentence_transformers import SentenceTransformer
from sentence_transformers import models
transformer = models.BERT('cl-tohoku/bert-base-japanese-whole-word-masking')

------------------- ERROR DETAILS ------------------------
arguments: [b'fugashi', b'-C', b'-d', b'C:UsersnwAnaconda3envsPyTorchCUDA10_1libsite-packagesipadicdicdir', b'-r', b'C:UsersnwAnaconda3envsPyTorchCUDA10_1libsite-packagesipadicdicdirmecabrc']
error message: param.cpp(69) [ifs] no such file or directory: C:UsersnwAnaconda3envsPyTorchCUDA10_1libsite-packagesipadicdicdirmecabrc
----------------------------------------------------------
RuntimeError: Failed initializing MeCab

となった。

そこで、transformersパッケージのtokenization_bert_japanese.pyの252行目に
mecabrc = os.path.join(dic_dir, "mecabrc")
mecab_option = "-d {} -r {} ".format(dic_dir, mecabrc) + mecab_option
mecab_option = mecab_option.replace('\','/')
replaceを追加し、事無きを得たように見える。
修正はこれでよいのだろうか。

@polm
Copy link
Owner

polm commented Sep 23, 2020

ご報告ありがとうございます。

問題の原因はshlexにあるみたいです。quoteされてない\が消えてしまいます。パスがquoteされてないせいで他のエラーも起きたので、修正PRは既にtransformersの方でマージされていますがリリースはまだです。

huggingface/transformers#7142

以上で起動できたらそれでも問題ありませんがPRの修正内容は下記です。これだとスペースのあるパスでも正しく処理されます。

mecab_option = '-d "{}" -r "{}" '.format(dic_dir, mecabrc) + mecab_option

@polm
Copy link
Owner

polm commented Sep 24, 2020

修正PRは既にマージされたので一応クローズします。

@polm polm closed this as completed Sep 24, 2020
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

2 participants