テキスト生成トランス:どのように使用する&どのように提供する


テキスト生成とは何かいくつかのテキストを入力し、モデルは、次のテキストがどのように予測されます.
面白いね.どのように自分自身でモデルを試しずに面白いことができますか?

ハウツーとスタイル


モデルは自動的にダウンロードされます
from transformers import pipeline, set_seed

generator = pipeline("text-generation", model="gpt2")
set_seed(42)


def predict(text):
    return generator(text, max_length=50, num_return_sequences=3)
それだ!
ちょっと試してみましょう
predict("You look amazing today,")
結果
[{'generated_text': 'You look amazing today, guys. If you\'re still in school and you still have a job where you work in the field… you\'re going to look ridiculous by now, you\'re going to look really ridiculous."\n\nHe turned to his friends'},
 {'generated_text': 'You look amazing today, aren\'t you?"\n\nHe turned and looked at me. He had an expression that was full of worry as he looked at me. Even before he told me I\'d have sex, he gave up after I told him'},
 {'generated_text': 'You look amazing today, and look amazing in the sunset."\n\nGarry, then 33, won the London Marathon at age 15, and the World Triathlon in 2007, the two youngest Olympians to ride 100-meters. He also'}]
最初の結果を見てみましょう.

You look amazing today, guys. If you're still in school and you still have a job where you work in the field… you're going to look ridiculous by now, you're going to look really ridiculous." 
He turned to his friends


🤣 それは我々が探しているものです!再度予測を実行すると、それは毎回異なる結果を与えるでしょう.

モデルを展開する


展開せずに、どのようにマシンの学習チュートリアルを完了することができますか?
まず、Pinferenciaをインストールしましょう.
pip install "pinferencia[uvicorn]"
あなたがPinferenciaがそのgithubページまたはそれをチェックするためにそのhomepageに行くのを聞いていないならば、それはあなたが簡単にモデルを展開するのを援助する驚くべきライブラリです.

サービスを作成する


今すぐアプリを作成しましょう.Pyファイル
from transformers import pipeline, set_seed

from pinferencia import Server

generator = pipeline("text-generation", model="gpt2")
set_seed(42)


def predict(text):
    return generator(text, max_length=50, num_return_sequences=3)


service = Server()
service.register(model_name="gpt2", model=predict)

サーバを起動する


uvicorn app:service --reload

サービスをテストする


あなたがテストするためにカールを使用するか、またはインタラクティブなUIを使用することができます
カール
curl -X 'POST' \
    'http://127.0.0.1:8000/v1/models/gpt2/predict' \
    -H 'accept: application/json' \
    -H 'Content-Type: application/json' \
    -d '{
        "id": "string",
        "parameters": {},
        "data": "You look amazing today,"
    }'
結果:
{
    "id": "string",
    "model_name": "gpt2",
    "data": [
        {
            "generated_text": "You look amazing today, I was in front of my friends. I wanted everyone to see me. But that's all. No one really cares about me in the eyes of the whole world unless I love them.\"\n\nIn a second Facebook post"
        },
        {
            "generated_text": "You look amazing today, and I know I am going to get the job done! So thank you all for all those donations, money, help, and hugs. I hope to see you again soon."
        },
        {
            "generated_text": "You look amazing today, but I will have to wait until early June for what will go down as the first NBA championship (a thing I had been expecting). If it's not the biggest, it is also not great. Now let's look at"
        }
    ]
}
も、クーラー、http://127.0.0.1:8000に行くと、インタラクティブなUIがあります.
あなただけの予測のリクエストを送信することができます!
行け!
Pinferencia

Pinferenciaのような場合は、に行くとスターを与えることを忘れないでください.