Google Colaboratory のページ:
次のリンクをクリックすると,Google Colaboratory のノートブックが開く. そして,Google アカウントでログインすると,Google Colaboratory のノートブック内のコード等を編集したり再実行したりができる.編集した場合でも,他の人に影響が出たりということはない.そして,編集後のものを,各自の Google ドライブ内に保存することもできる.
https://colab.research.google.com/drive/1mBFygBbUk4lBOov7TVyiat441MHwla3j?usp=sharing
Windows での Python 3.10,関連パッケージ,Python 開発環境のインストール: 別ページ »で説明
【サイト内の関連ページ】
Python のまとめ: 別ページ »にまとめ
【関連する外部ページ】
Python の公式ページ: https://www.python.org/
Windows での TensorFlow,Keras のインストール: 別ページ »で説明
(このページで,Build Tools for Visual Studio 2022,NVIDIA ドライバ, NVIDIA CUDA ツールキット, NVIDIA cuDNNのインストールも説明している.)
Windows での Graphviz のインストール: 別ページ »で説明
コマンドプロンプトを管理者として実行: 別ページ »で説明
python -m pip install -U numpy matplotlib seaborn scikit-learn pandas pydot
sudo apt -y insatll graphviz python3-graphviz libgraphviz-dev
huggingface/transformers の URL: https://huggingface.co/transformers/ huggingface/transformers の GitHub の URL: https://github.com/huggingface/transformers
次のページに記載の手順に従う:https://huggingface.co/transformers/installation.html
Windows では,コマンドプロンプトを管理者として開き次のコマンドを実行する.
python -m pip install transformers
次のページに記載のソースコードからビルドして,インストールする.(詳細説明も次のページにある): https://huggingface.co/gpt2
Python プログラムを動かすために, pythonやpython3などのコマンドを使う. あるいは, 開発環境や Python コンソール(Jupyter Qt Console,Spyder,PyCharm,PyScripter
次のプログラムは,テキスト生成(与えられた文章から,続きのトークンを生成)を行っている.
from transformers import pipeline, set_seed generator = pipeline('text-generation', model='gpt2') set_seed(42) generator("Hello, I'm a language model,", max_length=30, num_return_sequences=5)
次のプログラムは,特徴(features )の取得を行っている.
from transformers import GPT2Tokenizer, TFGPT2Model tokenizer = GPT2Tokenizer.from_pretrained('gpt2') model = TFGPT2Model.from_pretrained('gpt2') text = "Replace me by any text you'd like." encoded_input = tokenizer(text, return_tensors='tf') output = model(encoded_input)
次のページに記載のソースコードからビルドして,インストールする.(詳細説明も次のページにある): https://huggingface.co/bert-base-uncased
Python プログラムを動かすために, pythonやpython3などのコマンドを使う. あるいは, 開発環境や Python コンソール(Jupyter Qt Console,Spyder,PyCharm,PyScripter
次のプログラムは,マスクを埋める(fill mask)ことを行っている.
from transformers import pipeline unmasker = pipeline('fill-mask', model='bert-base-uncased') unmasker("Hello I'm a [MASK] model.")