2222
33223 ワード
レイアウトの追加
"keyword_matching_init.py"
if __name__ == "__main__":
data_path = "/home/ubuntu/src/script/curation/data"
...
...
file_list = os.listdir(data_path)
上記コードでバッチ処理を行う「data path」のファイル名を読み出し、それに基づいてバッチ処理を行う-バッチ処理中にエラーが発生した場合、通常data pathにcsv、xlsx拡張子以外のファイルが含まれている場合、im→非表示のファイルが存在する可能性があるため、cmd行で直接チェックする必要があります.
主観式自動採点適用状況リスト
subjective_question_verification
テーブルで検証できます.
-- 올바르게 채점한 수
select count(*) from "subjective_question_verification"
where "__time" >= '2021-07-14'
and correct_answer_rate < 10
and correct_answer_rate > 90
-- 총 채점 수
select count(*) from "subjective_question_verification"
where "__time" >= '2021-07-14'
3. GPT-3 Pricing
1 Token=英語4文字程度でOK簡単な単語でいいです.
4. GPT-3 Turorial
デフォルトではGPT-3を使用する準備ができています.では、PythonでGPT-3ライブラリをインストールして使用する方法について説明します.
まず、openaiライブラリを仮想環境にインストールします.
$ conda create --n gpt python=3.7
$ conda activate gpt
(gpt) $ pip install openai
インストールが完了したら、簡単なコードですぐにテストできます.import openai
openapi.api_key = "SECRET_API_KEY"
prompt = "This is a test"
response = openai.Completion.create(engine="davinci", prompt=prompt, max_tokens=10)
print(response.choices[0].text)
------------------------------------------------------------------------------------
' of whether the programming works correctly.\n\nHere'
5.例による学習
GPT−3はより性能の高いモデルであり,少量のshot学習によっていくつかの例を提供することができる.使用率を向上させるために、GPT classとExample classを以下のように作成できます.
(出典:https://github.com/shreyashankar/gpt3-sandbox)
"""Creates the Example and GPT classes for a user to interface with the OpenAI
API."""
import openai
import uuid
def set_openai_key(key):
"""Sets OpenAI key."""
openai.api_key = key
class Example:
"""Stores an input, output pair and formats it to prime the model."""
def __init__(self, inp, out):
self.input = inp
self.output = out
self.id = uuid.uuid4().hex
def get_input(self):
"""Returns the input of the example."""
return self.input
def get_output(self):
"""Returns the intended output of the example."""
return self.output
def get_id(self):
"""Returns the unique ID of the example."""
return self.id
def as_dict(self):
return {
"input": self.get_input(),
"output": self.get_output(),
"id": self.get_id(),
}
class GPT:
"""The main class for a user to interface with the OpenAI API.
A user can add examples and set parameters of the API request.
"""
def __init__(self,
engine='davinci',
temperature=0.5,
max_tokens=100,
input_prefix="input: ",
input_suffix="\n",
output_prefix="output: ",
output_suffix="\n\n",
append_output_prefix_to_query=False):
self.examples = {}
self.engine = engine
self.temperature = temperature
self.max_tokens = max_tokens
self.input_prefix = input_prefix
self.input_suffix = input_suffix
self.output_prefix = output_prefix
self.output_suffix = output_suffix
self.append_output_prefix_to_query = append_output_prefix_to_query
self.stop = (output_suffix + input_prefix).strip()
def add_example(self, ex):
"""Adds an example to the object.
Example must be an instance of the Example class.
"""
assert isinstance(ex, Example), "Please create an Example object."
self.examples[ex.get_id()] = ex
def delete_example(self, id):
"""Delete example with the specific id."""
if id in self.examples:
del self.examples[id]
def get_example(self, id):
"""Get a single example."""
return self.examples.get(id, None)
def get_all_examples(self):
"""Returns all examples as a list of dicts."""
return {k: v.as_dict() for k, v in self.examples.items()}
def get_prime_text(self):
"""Formats all examples to prime the model."""
return "".join(
[self.format_example(ex) for ex in self.examples.values()])
def get_engine(self):
"""Returns the engine specified for the API."""
return self.engine
def get_temperature(self):
"""Returns the temperature specified for the API."""
return self.temperature
def get_max_tokens(self):
"""Returns the max tokens specified for the API."""
return self.max_tokens
def craft_query(self, prompt):
"""Creates the query for the API request."""
q = self.get_prime_text(
) + self.input_prefix + prompt + self.input_suffix
if self.append_output_prefix_to_query:
q = q + self.output_prefix
return q
def submit_request(self, prompt):
"""Calls the OpenAI API with the specified parameters."""
response = openai.Completion.create(engine=self.get_engine(),
prompt=self.craft_query(prompt),
max_tokens=self.get_max_tokens(),
temperature=self.get_temperature(),
top_p=1,
n=1,
stream=False,
stop=self.stop)
return response
def get_top_reply(self, prompt):
"""Obtains the best result as returned by the API."""
response = self.submit_request(prompt)
return response['choices'][0]['text']
def format_example(self, ex):
"""Formats the input, output pair."""
return self.input_prefix + ex.get_input(
) + self.input_suffix + self.output_prefix + ex.get_output(
) + self.output_suffix
gpt.pyファイルを作成した場合は、サンプルを使用してクエリーを生成するgpt-3モデルについて学習します.gpt = GPT(engine="davinci",
temperature=0.5,
max_tokens=100)
gpt.add_example(Example('Fetch unique values of DEPARTMENT from Worker table.',
'Select distinct DEPARTMENT from Worker;'))
gpt.add_example(Example('Print the first three characters of FIRST_NAME from Worker table.',
'Select substring(FIRST_NAME,1,3) from Worker;'))
gpt.add_example(Example('Find the position of the alphabet ("a") in the first name column "Amitabh" from Worker table.',
'Select INSTR(FIRST_NAME, BINARY"a") from Worker where FIRST_NAME = "Amitabh";'))
gpt.add_example(Example('Print the FIRST_NAME from Worker table after replacing "a" with "A".',
'Select CONCAT(FIRST_NAME, " ", LAST_NAME) AS "COMPLETE_NAME" from Worker;'))
gpt.add_example(Example('Display the second highest salary from the Worker table.',
'Select max(Salary) from Worker where Salary not in (Select max(Salary) from Worker);'))
gpt.add_example(Example('Display the highest salary from the Worker table.',
'Select max(Salary) from Worker;'))
gpt.add_example(Example('Fetch the count of employees working in the department Admin.',
'SELECT COUNT(*) FROM worker WHERE DEPARTMENT = "Admin";'))
gpt.add_example(Example('Get all details of the workers whose SALARY lies between 100000 and 500000.',
'Select * from Worker where SALARY between 100000 and 500000;'))
gpt.add_example(Example('Get Salary details of the Workers',
'Select Salary from Worker'))
いくつかのクエリの例でGPT-3を学習した後、未学習のクエリをモデルに送信すると、次のクエリが生成されます.Reference
この問題について(2222), 我々は、より多くの情報をここで見つけました https://velog.io/@data-traveler/2222テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol