keep-loving-pythonのブログ

Pythonを愛し続けたいです(Pythonが流行っている限りですが。。。)

Python用語、日本語と英語の対比。

日本語と英語の対比

引用元

https://docs.python.org/ja/3/reference/expressions.html

https://docs.python.org/3/reference/expressions.html

対比

日本語 英語 備考
ブール演算 Boolean operations 論理演算って用語じゃないんだよねーー。

補足

以前お世話になった以下の記事の勝手に後継!

qiita.com

コメント

これからどんどん増やします。予定。。。。!

解決策。ConnectionResetError: [WinError 10054] 既存の接続はリモート ホストに強制的に切断されました。wandb関連。

エラー

ConnectionResetError: [WinError 10054] 既存の接続はリモート ホストに強制的に切断されました。

エラー詳細

Exception in thread ChkStopThr:
Traceback (most recent call last):
  File "C:\Users\XYZZZ\AppData\Local\Programs\Python\Python37\lib\threading.py", line 917, in _bootstrap_inner
    self.run()
  File "C:\Users\XYZZZ\AppData\Local\Programs\Python\Python37\lib\threading.py", line 865, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\XYZZZ\AppData\Local\Programs\Python\Python37\lib\site-packages\wandb\sdk\wandb_run.py", line 203, in check_status
    status_response = self._interface.communicate_stop_status()
  File "C:\Users\XYZZZ\AppData\Local\Programs\Python\Python37\lib\site-packages\wandb\sdk\interface\interface.py", line 127, in communicate_stop_status
    resp = self._communicate_stop_status(status)
  File "C:\Users\XYZZZ\AppData\Local\Programs\Python\Python37\lib\site-packages\wandb\sdk\interface\interface_sock.py", line 69, in _communicate_stop_status
    data = super()._communicate_stop_status(status)
  File "C:\Users\XYZZZ\AppData\Local\Programs\Python\Python37\lib\site-packages\wandb\sdk\interface\interface_shared.py", line 400, in _communicate_stop_status
    resp = self._communicate(req, local=True)
  File "C:\Users\XYZZZ\AppData\Local\Programs\Python\Python37\lib\site-packages\wandb\sdk\interface\interface_shared.py", line 231, in _communicate
    return self._communicate_async(rec, local=local).get(timeout=timeout)
  File "C:\Users\XYZZZ\AppData\Local\Programs\Python\Python37\lib\site-packages\wandb\sdk\interface\interface_sock.py", line 58, in _communicate_async
    future = self._router.send_and_receive(rec, local=local)
  File "C:\Users\XYZZZ\AppData\Local\Programs\Python\Python37\lib\site-packages\wandb\sdk\interface\router.py", line 93, in send_and_receive
    self._send_message(rec)
  File "C:\Users\XYZZZ\AppData\Local\Programs\Python\Python37\lib\site-packages\wandb\sdk\interface\router_sock.py", line 35, in _send_message
    self._sock_client.send_record_communicate(record)
  File "C:\Users\XYZZZ\AppData\Local\Programs\Python\Python37\lib\site-packages\wandb\sdk\lib\sock_client.py", line 145, in send_record_communicate
    self.send_server_request(server_req)
  File "C:\Users\XYZZZ\AppData\Local\Programs\Python\Python37\lib\site-packages\wandb\sdk\lib\sock_client.py", line 84, in send_server_request
    self._send_message(msg)
  File "C:\Users\XYZZZ\AppData\Local\Programs\Python\Python37\lib\site-packages\wandb\sdk\lib\sock_client.py", line 81, in _send_message
    self._sendall_with_error_handle(header + data)
  File "C:\Users\XYZZZ\AppData\Local\Programs\Python\Python37\lib\site-packages\wandb\sdk\lib\sock_client.py", line 61, in _sendall_with_error_handle
    sent = self._sock.send(data[total_sent:])
ConnectionResetError: [WinError 10054] 既存の接続はリモート ホストに強制的に切断されました。

環境

windows10
python3.7

transformers 4.28.1

wandb 0.13.2

解決策

その前に

なぜ、wandbというのが動いているのかも不明。
コード内に、そのような記載はない。
transformersの関連だと思っている。 バージョンが「 4.28.1」で新しいからかな???

解決策1

コマンドプロンプトにて、
wandbをとめた
(環境変数とかでも止められるでしょう。)

>wandb disabled

解決策2

そもそも、上記のエラー、もう一回実行したらエラー出なかった。
また、実害ないから無視でもいいのでは?

コメント

wandbが何者か、あまりわからずに書いてます。 アドバイスあれば、コメント下さい(コメントもらえたことないけど。。。是非)

解決策。No module named 'tensorflow.python.keras.engine.keras_tensor'。

エラー

環境

windows10
python3.7

エラー

No module named 'tensorflow.python.keras.engine.keras_tensor'

エラー詳細

Traceback (most recent call last):
  File "C:\Users\XYZZZ\AppData\Local\Programs\Python\Python37\lib\site-packages\transformers\file_utils.py", line 2777, in _get_module
    return importlib.import_module("." + module_name, self.__name__)
  File "C:\Users\XYZZZ\AppData\Local\Programs\Python\Python37\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "C:\Users\XYZZZ\AppData\Local\Programs\Python\Python37\lib\site-packages\transformers\models\roberta\modeling_tf_roberta.py", line 43, in <module>
    from ...modeling_tf_utils import (
  File "C:\Users\XYZZZ\AppData\Local\Programs\Python\Python37\lib\site-packages\transformers\modeling_tf_utils.py", line 31, in <module>
    from tensorflow.python.keras.engine.keras_tensor import KerasTensor
ModuleNotFoundError: No module named 'tensorflow.python.keras.engine.keras_tensor'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "BERT_from_scratch.py", line 373, in <module>
    fill = pipeline('fill-mask', model='liberto', tokenizer='liberto')
  File "C:\Users\XYZZZ\AppData\Local\Programs\Python\Python37\lib\site-packages\transformers\pipelines\__init__.py", line 556, in pipeline
    **model_kwargs,
  File "C:\Users\XYZZZ\AppData\Local\Programs\Python\Python37\lib\site-packages\transformers\pipelines\base.py", line 223, in infer_framework_load_model
    _class = getattr(transformers_module, f"TF{architecture}", None)
  File "C:\Users\XYZZZ\AppData\Local\Programs\Python\Python37\lib\site-packages\transformers\file_utils.py", line 2768, in __getattr__
    value = getattr(module, name)
  File "C:\Users\XYZZZ\AppData\Local\Programs\Python\Python37\lib\site-packages\transformers\file_utils.py", line 2767, in __getattr__
    module = self._get_module(self._class_to_module[name])
  File "C:\Users\XYZZZ\AppData\Local\Programs\Python\Python37\lib\site-packages\transformers\file_utils.py", line 2781, in _get_module
    ) from e
RuntimeError: Failed to import transformers.models.roberta.modeling_tf_roberta because of the following error (look up to see its traceback):
No module named 'tensorflow.python.keras.engine.keras_tensor'

解決策

python -m pip install tensorflow==2.3.0

コメント

アドバイスあれば、お願いします。

解決策。ImportError: cannot import name 'naming' from 'tensorflow.python.autograph.core'。

エラー

環境

windows10
python3.7

エラー

ImportError: cannot import name 'naming' from 'tensorflow.python.autograph.core'
cannot import name 'naming' from 'tensorflow.python.autograph.core'

エラー詳細

>python
Python 3.7.2 (tags/v3.7.2:9a3ffc0492, Dec 23 2018, 23:09:28) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from transformers import pipeline
2023-05-01 19:42:12.295722: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'cudart64_101.dll'; dlerror: cudart64_101.dll not found
2023-05-01 19:42:12.310752: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
Traceback (most recent call last):
  File "C:\Users\XYZZZ\AppData\Local\Programs\Python\Python37\lib\site-packages\transformers\utils\import_utils.py", line 1146, in _get_module
    return importlib.import_module("." + module_name, self.__name__)
  File "C:\Users\XYZZZ\AppData\Local\Programs\Python\Python37\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "C:\Users\XYZZZ\AppData\Local\Programs\Python\Python37\lib\site-packages\transformers\pipelines\__init__.py", line 68, in <module>
    from .table_question_answering import TableQuestionAnsweringArgumentHandler, TableQuestionAnsweringPipeline
  File "C:\Users\XYZZZ\AppData\Local\Programs\Python\Python37\lib\site-packages\transformers\pipelines\table_question_answering.py", line 26, in <module>
    import tensorflow_probability as tfp
  File "C:\Users\XYZZZ\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_probability\__init__.py", line 75, in <module>
    from tensorflow_probability.python import *  # pylint: disable=wildcard-import
  File "C:\Users\XYZZZ\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_probability\python\__init__.py", line 24, in <module>
    from tensorflow_probability.python import experimental
  File "C:\Users\XYZZZ\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_probability\python\experimental\__init__.py", line 34, in <module>
    from tensorflow_probability.python.experimental import auto_batching
  File "C:\Users\XYZZZ\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_probability\python\experimental\auto_batching\__init__.py", line 24, in <module>
    from tensorflow_probability.python.experimental.auto_batching import frontend
  File "C:\Users\XYZZZ\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow_probability\python\experimental\auto_batching\frontend.py", line 44, in <module>
    from tensorflow.python.autograph.core import naming
ImportError: cannot import name 'naming' from 'tensorflow.python.autograph.core' (C:\Users\XYZZZ\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\autograph\core\__init__.py)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<frozen importlib._bootstrap>", line 1032, in _handle_fromlist
  File "C:\Users\XYZZZ\AppData\Local\Programs\Python\Python37\lib\site-packages\transformers\utils\import_utils.py", line 1136, in __getattr__
    module = self._get_module(self._class_to_module[name])
  File "C:\Users\XYZZZ\AppData\Local\Programs\Python\Python37\lib\site-packages\transformers\utils\import_utils.py", line 1151, in _get_module
    ) from e
RuntimeError: Failed to import transformers.pipelines because of the following error (look up to see its traceback):
cannot import name 'naming' from 'tensorflow.python.autograph.core' (C:\Users\XYZZZ\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\python\autograph\core\__init__.py)
>>>

解決策

すみません、どれが有効打か、ちょっと、不正確。

python -m pip install tensorflow-probability==0.7.0

↓ もしかすると、これも関係するかも。。。

python -m pip install tfp-nightly==0.11.0.dev20200708

現状のモジュール構成

↓ どれが意味があるのか、よくわかっていません。

keras                             2.11.0

tensorflow                        2.3.1

tensorflow-probability            0.7.0

tfp-nightly                       0.11.0.dev20200708

torch                             1.10.2

transformers                      4.28.1

コメント

すっきりした情報あれば、コメントで教えて下さい!!!是非!!!

breaking change とは?

breaking change とは? Stackoverflowより。

Q:私たちの会社では、壊れるような変化(breaking change)とは何かという定義があり、なるべく避けようと思っています。

それは、「変化」です。

  • メソッドのシグネチャを変更するもの。
  • メソッドの動作を変更する。
  • 設定やコンフィギュレーションを変更する。
  • モジュールやアセンブリなどの依存関係を追加する。 これは、ブレークチェンジの定義として適切なものでしょうか?何か欠けているものはないでしょうか?データベーススキーマの変更もブレークチェンジと言えるでしょうか(新しいカラムや新しいテーブルなど)?

A:最初のポイントは、「breaking change」が英語*で何を意味するのかを決めることです。ある場所では、単にコードのコンパイルや実行を停止させるものである場合もあります。

あなたのこれまでのリストからは、他の人が対応する変更をする必要があるような変更のことを指しているのでしょう。その場合、製品の各モジュールは明確に定義されたインターフェース(他のモジュール、パブリックRESTインターフェース、システムのファイルシステムgui、ウェブアプリなど)を持っているはずなので、これらのインターフェースの1つから何かを取り除く(あるいは、それらの使用に関する新しい要件を追加する)ような変更が壊れる変更となります - 実質的には、製品の前のバージョンを使って、変更のあるモジュールだけを交換できない場合、それは壊す変更となります。

つまり、データベースの変更は、通常、破壊的な変更となります(必要に応じて自動アップグレードや自動ダウングレードを行うコードがある場合を除く)。

モジュール内の変更や、文書化されていないインターフェース(つまり、使ってはいけないもの)の変更は、壊れるような変更ではありません。もし、そのようなことが原因で製品が壊れてしまうのであれば、それはカプセル化の失敗である。

*または、あなたの(人間の)選択した言語です。

↑出典

アルクの説明

stackoverflow.com

《a ~》《コ》〔バージョンアップなどにおける〕互換性を破る変更

引用元

eow.alc.co.jp

コメント

DeepLの「breaking change」の訳がいまいちだったので。。。

Transformers v4。Breaking changes since v3.x。(Transformersのバージョン差でエラーに出会うことが多いと思うので。。)

情報元 (Dec 1, 2020)

github.com

Breaking changes since v3.x

1. AutoTokenizers and pipelines now use fast (rust) tokenizers by default.

pythonとrustのトークナイザーはほぼ同じAPIを持っていますが、rustのトークナイザーはより完全な機能セットを持っています。主な変更点は、pythonとrustのトークナイザーの間でオーバーフローしたトークンの処理です。

2. SentencePiece is removed from the required dependencies

SentencePiece依存の要件はsetup.pyから解除されました。これは、conda-forgeに依存することなく、anaconda cloud上でチャネルを持つことができるようにするためです。これは、SentencePieceライブラリに依存するトークナイザーが、標準的なトランスフォーマーのインストールで利用できなくなることを意味します。

3. The architecture of the repo has been updated so that each model resides in its folder

過去にも、そしてこれからも新しいモデルが追加されることは、src/transformersディレクトリのファイル数が増え続け、ナビゲートや理解が難しくなることを意味します。そこで、各モデルとそれに付随するファイルをそれぞれのサブディレクトリに置くという選択をしました。

これは、モデルのモジュールを直接使って中間層をインポートする場合、別の経路で行う必要があるため、画期的な変更です。

4. Switching the return_dict argument to True by default

return_dict引数は、標準的なタプルの代わりに、モデル出力を含む名前付きタプルのようなpythonオブジェクトを返すことを可能にします。このオブジェクトは、キーが値を取得するために使用されるように自己文書化されており、また、ユーザがインデックスまたはスライスによってオブジェクトを取得できるようにタプルとして振る舞うことができます。

このタプルの限界は、value0, value1 = outputsのように解凍できないことなので、これは画期的な変更です。

5. Removed some deprecated attributes

非推奨だった属性は、少なくとも1ヶ月間非推奨だった場合、削除されました。非推奨属性の全リストは#8604で見ることができます。

ここでは、これらの属性/メソッド/引数のリストと、その代替となるべきものを示します:

いくつかのモデルで、ラベルが他のモデルと一致するようになりました:

解決策。ValueError: time data 'Jun 15' does not match format '%m %d' (match)。pandas。

エラー

ValueError: time data 'Jun 15' does not match format '%m %d' (match)

エラー詳細

Traceback (most recent call last):
  File "C:\Users\XYZZZ\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\core\tools\datetimes.py", line 509, in _to_datetime_with_format
    values, tz = conversion.datetime_to_datetime64(arg)
  File "pandas\_libs\tslibs\conversion.pyx", line 359, in pandas._libs.tslibs.conversion.datetime_to_datetime64
TypeError: Unrecognized value type: <class 'str'>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "_pandas_datetime4.py", line 7, in <module>
    df["Date"] = pd.to_datetime(df["Month"]+" "+df["Day"].astype(str), format="%m %d")
  File "C:\Users\XYZZZ\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\core\tools\datetimes.py", line 887, in to_datetime
    values = convert_listlike(arg._values, format)
  File "C:\Users\XYZZZ\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\core\tools\datetimes.py", line 394, in _convert_listlike_datetimes
    arg, orig_arg, name, tz, format, exact, errors, infer_datetime_format
  File "C:\Users\XYZZZ\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\core\tools\datetimes.py", line 513, in _to_datetime_with_format
    raise err
  File "C:\Users\XYZZZ\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\core\tools\datetimes.py", line 501, in _to_datetime_with_format
    arg, name, tz, fmt, exact, errors, infer_datetime_format
  File "C:\Users\XYZZZ\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\core\tools\datetimes.py", line 436, in _array_strptime_with_fallback
    result, timezones = array_strptime(arg, fmt, exact=exact, errors=errors)
  File "pandas\_libs\tslibs\strptime.pyx", line 150, in pandas._libs.tslibs.strptime.array_strptime
ValueError: time data 'Jun 15' does not match format '%m %d' (match)

環境

windows10
python3.7
pandas1.3.5

エラーが発生するコード

import pandas as pd

df = pd.DataFrame({"Month":["Jun"],"Day":[15]})
##df["Date"] = pd.to_datetime(df["D"])
df["Date"] = pd.to_datetime(df["Month"]+" "+df["Day"].astype(str), format="%m %d")
print(df["Date"])

解決策

mじゃなくてbです
フォーマット指定子は、ちゃんとしてないとダメみたい。

df["Date"] = pd.to_datetime(df["Month"]+" "+df["Day"].astype(str), format="%b %d")

参考にすべきサイト

www.yutaka-note.com

引用↓

コメント

特にありません。