プロンプトマトリックスは、プロンプトマトリックスを指定する文字列を展開する小さなPythonパッケージです。たとえば、 "The <dog|cat> in the hat"
弦はリストに拡大します["The dog in the hat", "The cat in the hat"]
。
このパッケージの動機付けケースは、安定した拡散やGPT-3などのテキストと画像生成システムのさまざまなプロンプトの効果を比較することです。
プロンプト文字列には複数の代替が含まれる場合があります。たとえば、 "The <dog|cat> in the <cardigan|hat>"
"The dog in the cardigan"
、 "The dog in the hat"
、 "The cat in the cardigan"
、および4つのひものリストを作成します。 "The cat in the hat"
。
プロンプトの文字列には、ネストされた交互に含まれる場合があります。たとえば、 "The <<small|large> dog|cat>"
"The small dog"
、 "The large do"
、 "The cat"
を生成します。
ブラケット[]
オプションの要素を囲みます。たとえば、 "The [small] cat"
"The <small,> cat"
と同等であり、どちらも"The small cat"
と"The cat"
弦を生成します。
特殊文字<>{}|
異なる文字列に置き換えたり、 None
または空の文字列を指定して無効にすることもできます。
注:分離は、囲まれた括弧があれば囲まれていることに囲まれています。
"The dog|cat in the cardigan|hat"
3つのひも"The dog"
、"cat in the gardigan"
、"hat"
を生成します。これは、周囲の空白によって区切られたテキストの分離を範囲する他のシステムとは対照的です。
$ pip install prompt-matrix
プロンプトマトリックスは、プロンプトマトリックスを拡張するための2つの機能を提供します: expand
とiterexpand
。両方とも、プロンプトマトリックスを指定する文字列を撮影します。
expand
プロンプトマトリックス要素のすべての可能な組み合わせを備えた一連の文字列を返します。
import prompt_matrix
prompt = "<hi|hello> <there|you>"
expansion = prompt_matrix . expand ( prompt )
print ( expansion ) # ["hi there", "hi you", "hello there", "hello you"]
iterexpand
拡張を1つずつ生成するジェネレーターを返します。
import prompt_matrix
prompt = "<hi|hello> <there|you>"
for expansion in prompt_matrix . iterexpand ( prompt ):
print ( expansion ) # "hi there", "hi you", "hello there", "hello you"
例1:基本的な使用法
import prompt_matrix
prompt_matrix . expand ( "The <dog|cat> in the hat" )
# ->
# ["The dog in the hat",
# "The cat in the hat"]
例2:複数の代替を使用します
prompt_matrix . expand ( "The <dog|cat> in the <cardigan|hat>" )
# ->
# ["The dog in the cardigan",
# "The dog in the hat",
# "The cat in the cardigan",
# "The cat in the hat"]
例3:ネストされたブラケットの使用
prompt_matrix . expand ( "The <<small|large> <brown|black> dog|<red|blue> fish>" )
# ->
# ["The small brown dog",
# "The small black dog",
# "The large brown dog",
# "The large black dog",
# "The red fish",
# "The blue fish"]
例4:カスタムブラケットとセパレーターの使用
prompt_matrix . expand ( "The {dog,cat} in the {cardigan,hat}" ,
brackets = [ '{' , '}' ], alt = ',' )
# ->
# ["The dog in the cardigan",
# "The dog in the hat",
# "The cat in the cardigan",
# "The cat in the hat"]
このライブラリのJavaScriptバージョンは、https://github.com/osteele/prompt-matrix.pyにあります。
mit