0
0

asariを実行した時に発生したロケールのエラーの対処

Posted at

SageMaker Notebookインスタンス上で、asariを使って日本語の感情分析(ポジティブ・ネガティブ)を実行しようとした時に発生したエラーと対処方法を記録したメモです。

発生したエラー

実行コマンド on Jupyter Noteboook

! pip install asari

from asari.api import Sonar

sonar = Sonar()

発生したエラーメッセージ

RuntimeException: [ONNXRuntimeError] : 6 : RUNTIME_EXCEPTION : Exception during initialization: /onnxruntime_src/onnxruntime/core/providers/cpu/nn/string_normalizer.cc:100 onnxruntime::string_normalizer::Locale::Locale(const string&)::<lambda()> Failed to construct locale with name:en_US.UTF-8:locale::facet::_S_create_c_locale name not valid:Please, install necessary language-pack-XX and configure locales

原因は、ロケールの初期化において、en_US.UTF-8 という名前のロケールの構築に失敗していることのようだ。

対処例

en_US.UTF-8をインストールして設定することで対処する。

(1) ロケールの一覧を確認 (en_US.UTF-8は無い)

!locale -a

(2) language-pack-enをインストールする

!sudo apt-get update
!sudo apt-get install -y language-pack-en

(3) 再度ロケールの一覧を確認 (en_US.UTF-8が存在する)

!locale -a

(4) ロケール設定を更新

# !sudo update-locale LANG=en_US.UTF-8 

(5) Notebookのカーネルを再起動

対処後

これでエラーなくasariが実行できるようになった。

from asari.api import Sonar
sonar = Sonar()
sonar.ping('今日はとても良い天気です')

# 実行結果
# {'text': '今日はとても良い天気です',
# 'top_class': 'positive',
# 'classes': [{'class_name': 'negative', 'confidence': 0.006367480847984552},
#  {'class_name': 'positive', 'confidence': 0.9936324954032898}]}

(参考) 実行環境

!pip list | egrep "asari|Janome"
# asari                                 0.2.0
# Janome                                0.4.2
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0