mchappychen / michaelchen.app

Transcribing app
0 stars 0 forks source link

Improve name recognition #2

Open mchappychen opened 1 month ago

mchappychen commented 1 month ago

"My name is ..."

"...NAME...?" "..."

Option 1: Combine NLTK with spacey:

import spacy

nlp = spacy.load("en_core_web_sm")
doc = nlp(input())

person_list = []
for ent in doc.ents:
    if ent.label_ == "PERSON":
        person_list.append(ent.text)

Option 2: Call a LLM api like chatgpt for it:

import openai

# Your OpenAI API key
api_key = "your-api-key"

# The text you want to analyze
text = """
[Insert the text you provided here]
"""

# OpenAI API call to ask ChatGPT to identify names
response = openai.Completion.create(
    engine="text-davinci-002",
    prompt=text,
    max_tokens=100,
    stop=["\n"]
)

# Extracting names from the response
names = []
for choice in response.choices:
    names.extend(choice.text.strip().split("\n"))

# Printing the identified names
print("Names identified by ChatGPT:")
for name in names:
    print(name)
mchappychen commented 1 month ago

https://github.com/xtekky/gpt4free?tab=readme-ov-file

Can also use gpt4free:

from g4f.client import Client

client = Client()
response = client.chat.completions.create(
    model="gpt-3.5-turbo",
    messages=[{"role": "user", "content": "What are all the names in this text:"}]
)
print(response.choices[0].message.content)