Skip to content

Instantly share code, notes, and snippets.

@rfeers
Created December 19, 2023 16:16
Show Gist options
  • Save rfeers/98ce6b819c726477b7a02c1731937291 to your computer and use it in GitHub Desktop.
Save rfeers/98ce6b819c726477b7a02c1731937291 to your computer and use it in GitHub Desktop.
def keyword_extraction(review):
response = openai.completions.create(
model="text-davinci-003", # You can choose the model version
prompt=f"""Analyze the following review: \"{review}\".
Identify the product that the user is reviewing and answer the product name with one or two words""",
max_tokens=60
)
sentiment = response.choices[0].text.strip()
return sentiment
df_short["Product"] = df_short.apply(lambda x:keyword_extraction(x["Text"]), axis=1)
df_short
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment