In [ ]:
Copied!
import pandas as pd
from openai import OpenAI
import re
import time
import pickle
import pandas as pd
from openai import OpenAI
import re
import time
import pickle
In [ ]:
Copied!
df = pd.read_csv('./dataset/raw.csv', )
df = pd.read_csv('./dataset/raw.csv', )
In [ ]:
Copied!
df
df
In [ ]:
Copied!
client = OpenAI(base_url="http://localhost:1234/v1", api_key="lm-studio")
client = OpenAI(base_url="http://localhost:1234/v1", api_key="lm-studio")
In [ ]:
Copied!
def get_text_between_quotes(input_string):
pattern = r'"([^"]*)"'
matches = re.findall(pattern, input_string)
try:
return matches[0]
except Exception as e:
return input_string
def get_text_between_quotes(input_string):
pattern = r'"([^"]*)"'
matches = re.findall(pattern, input_string)
try:
return matches[0]
except Exception as e:
return input_string
Zero shot generate¶
Test¶
In [ ]:
Copied!
promt = """
Generate formal script 1 paragraph to introduce with these information
- name: {}
- age: {}
- job: {}
"""
data = df.loc[0]
start_time = time.time()
completion = client.chat.completions.create(
model="lmstudio-community/Meta-Llama-3-8B-Instruct-GGUF",
messages=[
{"role": "system", "content": "Provide only answer don't repeat the question."},
{"role": "user", "content": promt.format(data["name"], data["age"], data["job"])}
],
temperature=0,
)
content = completion.choices[0].message.content
text = get_text_between_quotes(content)
end_time = time.time()
print(f"Time use: {end_time - start_time} -- text: {text}")
promt = """
Generate formal script 1 paragraph to introduce with these information
- name: {}
- age: {}
- job: {}
"""
data = df.loc[0]
start_time = time.time()
completion = client.chat.completions.create(
model="lmstudio-community/Meta-Llama-3-8B-Instruct-GGUF",
messages=[
{"role": "system", "content": "Provide only answer don't repeat the question."},
{"role": "user", "content": promt.format(data["name"], data["age"], data["job"])}
],
temperature=0,
)
content = completion.choices[0].message.content
text = get_text_between_quotes(content)
end_time = time.time()
print(f"Time use: {end_time - start_time} -- text: {text}")
In [ ]:
Copied!
promt = """
Generate informal script 1 paragraph to introduce with these information
- name: {}
- age: {}
- job: {}
"""
data = df.loc[0]
start_time = time.time()
completion = client.chat.completions.create(
model="lmstudio-community/Meta-Llama-3-8B-Instruct-GGUF",
messages=[
{"role": "system", "content": "Provide only answer don't repeat the question."},
{"role": "user", "content": promt.format(data["name"], data["age"], data["job"])}
],
temperature=0,
)
content = completion.choices[0].message.content
text = get_text_between_quotes(content)
end_time = time.time()
print(f"Time use: {end_time - start_time} -- text: {text}")
promt = """
Generate informal script 1 paragraph to introduce with these information
- name: {}
- age: {}
- job: {}
"""
data = df.loc[0]
start_time = time.time()
completion = client.chat.completions.create(
model="lmstudio-community/Meta-Llama-3-8B-Instruct-GGUF",
messages=[
{"role": "system", "content": "Provide only answer don't repeat the question."},
{"role": "user", "content": promt.format(data["name"], data["age"], data["job"])}
],
temperature=0,
)
content = completion.choices[0].message.content
text = get_text_between_quotes(content)
end_time = time.time()
print(f"Time use: {end_time - start_time} -- text: {text}")
In [ ]:
Copied!
promt = """
Generate 1 paragraph story which include following information
- name: {}
- age: {}
- job: {}
"""
data = df.loc[0]
start_time = time.time()
completion = client.chat.completions.create(
model="lmstudio-community/Meta-Llama-3-8B-Instruct-GGUF",
messages=[
{"role": "system", "content": "Provide only answer don't repeat the question."},
{"role": "user", "content": promt.format(data["name"], data["age"], data["job"])}
],
temperature=0,
)
content = completion.choices[0].message.content
text = get_text_between_quotes(content)
end_time = time.time()
print(f"Time use: {end_time - start_time} -- text: {text}")
promt = """
Generate 1 paragraph story which include following information
- name: {}
- age: {}
- job: {}
"""
data = df.loc[0]
start_time = time.time()
completion = client.chat.completions.create(
model="lmstudio-community/Meta-Llama-3-8B-Instruct-GGUF",
messages=[
{"role": "system", "content": "Provide only answer don't repeat the question."},
{"role": "user", "content": promt.format(data["name"], data["age"], data["job"])}
],
temperature=0,
)
content = completion.choices[0].message.content
text = get_text_between_quotes(content)
end_time = time.time()
print(f"Time use: {end_time - start_time} -- text: {text}")
In [ ]:
Copied!
promt = """
Generate 1 paragraph story which include following information
- name: {}
- age: {}
- job: {}
"""
data = df.loc[0]
start_time = time.time()
completion = client.chat.completions.create(
model="lmstudio-community/Meta-Llama-3-8B-Instruct-GGUF",
messages=[
{"role": "system", "content": "Provide only answer don't repeat the question."},
{"role": "user", "content": promt.format(data["name"], data["age"], data["job"])}
],
temperature=0,
)
content = completion.choices[0].message.content
text = get_text_between_quotes(content)
end_time = time.time()
print(f"Time use: {end_time - start_time} -- text: {text}")
promt = """
Generate 1 paragraph story which include following information
- name: {}
- age: {}
- job: {}
"""
data = df.loc[0]
start_time = time.time()
completion = client.chat.completions.create(
model="lmstudio-community/Meta-Llama-3-8B-Instruct-GGUF",
messages=[
{"role": "system", "content": "Provide only answer don't repeat the question."},
{"role": "user", "content": promt.format(data["name"], data["age"], data["job"])}
],
temperature=0,
)
content = completion.choices[0].message.content
text = get_text_between_quotes(content)
end_time = time.time()
print(f"Time use: {end_time - start_time} -- text: {text}")
Generate zero shot¶
In [ ]:
Copied!
formal_script = {}
# for temp in [0, 0.3, 0.8, 1.3]:
for temp in [0.8]:
promt = """
Generate formal script 1 paragraph to introduce with these information
- name: {}
- age: {}
- job: {}
"""
key = f"temp_{temp}"
formal_script[key] = {}
for _, data in df.iterrows():
completion = client.chat.completions.create(
model="lmstudio-community/Meta-Llama-3-8B-Instruct-GGUF",
messages=[
{"role": "system", "content": "Provide only answer don't repeat the question."},
{"role": "user", "content": promt.format(data["name"], data["age"], data["job"])}
],
temperature=temp,
)
content = completion.choices[0].message.content
try:
text = get_text_between_quotes(content)
except Exception as e:
text = content
formal_script[key][data["uid"]] = text
formal_script = {}
# for temp in [0, 0.3, 0.8, 1.3]:
for temp in [0.8]:
promt = """
Generate formal script 1 paragraph to introduce with these information
- name: {}
- age: {}
- job: {}
"""
key = f"temp_{temp}"
formal_script[key] = {}
for _, data in df.iterrows():
completion = client.chat.completions.create(
model="lmstudio-community/Meta-Llama-3-8B-Instruct-GGUF",
messages=[
{"role": "system", "content": "Provide only answer don't repeat the question."},
{"role": "user", "content": promt.format(data["name"], data["age"], data["job"])}
],
temperature=temp,
)
content = completion.choices[0].message.content
try:
text = get_text_between_quotes(content)
except Exception as e:
text = content
formal_script[key][data["uid"]] = text
In [ ]:
Copied!
with open('./dataset/formal_script.pkl', 'wb') as fp:
pickle.dump(formal_script, fp)
with open('./dataset/formal_script.pkl', 'wb') as fp:
pickle.dump(formal_script, fp)
In [ ]:
Copied!
informal_script = {}
# for temp in [0, 0.3, 0.8, 1.3]:
for temp in [0.8]:
promt = """
Generate informal script 1 paragraph to introduce with these information
- name: {}
- age: {}
- job: {}
"""
key = f"temp_{temp}"
informal_script[key] = {}
for _, data in df.iterrows():
completion = client.chat.completions.create(
model="lmstudio-community/Meta-Llama-3-8B-Instruct-GGUF",
messages=[
{"role": "system", "content": "Provide only answer don't repeat the question."},
{"role": "user", "content": promt.format(data["name"], data["age"], data["job"])}
],
temperature=temp,
)
content = completion.choices[0].message.content
try:
text = get_text_between_quotes(content)
except Exception as e:
text = content
informal_script[key][data["uid"]] = text
informal_script = {}
# for temp in [0, 0.3, 0.8, 1.3]:
for temp in [0.8]:
promt = """
Generate informal script 1 paragraph to introduce with these information
- name: {}
- age: {}
- job: {}
"""
key = f"temp_{temp}"
informal_script[key] = {}
for _, data in df.iterrows():
completion = client.chat.completions.create(
model="lmstudio-community/Meta-Llama-3-8B-Instruct-GGUF",
messages=[
{"role": "system", "content": "Provide only answer don't repeat the question."},
{"role": "user", "content": promt.format(data["name"], data["age"], data["job"])}
],
temperature=temp,
)
content = completion.choices[0].message.content
try:
text = get_text_between_quotes(content)
except Exception as e:
text = content
informal_script[key][data["uid"]] = text
In [ ]:
Copied!
with open('./dataset/informal_script.pkl', 'wb') as fp:
pickle.dump(informal_script, fp)
with open('./dataset/informal_script.pkl', 'wb') as fp:
pickle.dump(informal_script, fp)
In [ ]:
Copied!
novel_script = {}
# for temp in [0, 0.3, 0.8, 1.3]:
for temp in [0.8]:
promt = """
Generate 1 paragraph story which include following information
- name: {}
- age: {}
- job: {}
"""
key = f"temp_{temp}"
novel_script[key] = {}
for _, data in df.iterrows():
completion = client.chat.completions.create(
model="lmstudio-community/Meta-Llama-3-8B-Instruct-GGUF",
messages=[
{"role": "system", "content": "Provide only answer don't repeat the question."},
{"role": "user", "content": promt.format(data["name"], data["age"], data["job"])}
],
temperature=temp,
)
content = completion.choices[0].message.content
try:
text = get_text_between_quotes(content)
except Exception as e:
text = content
novel_script[key][data["uid"]] = text
novel_script = {}
# for temp in [0, 0.3, 0.8, 1.3]:
for temp in [0.8]:
promt = """
Generate 1 paragraph story which include following information
- name: {}
- age: {}
- job: {}
"""
key = f"temp_{temp}"
novel_script[key] = {}
for _, data in df.iterrows():
completion = client.chat.completions.create(
model="lmstudio-community/Meta-Llama-3-8B-Instruct-GGUF",
messages=[
{"role": "system", "content": "Provide only answer don't repeat the question."},
{"role": "user", "content": promt.format(data["name"], data["age"], data["job"])}
],
temperature=temp,
)
content = completion.choices[0].message.content
try:
text = get_text_between_quotes(content)
except Exception as e:
text = content
novel_script[key][data["uid"]] = text
In [ ]:
Copied!
with open('./dataset/novel_script.pkl', 'wb') as fp:
pickle.dump(novel_script, fp)
with open('./dataset/novel_script.pkl', 'wb') as fp:
pickle.dump(novel_script, fp)
In [ ]:
Copied!
In [ ]:
Copied!