반응형
블로그 이미지
개발자로서 현장에서 일하면서 새로 접하는 기술들이나 알게된 정보 등을 정리하기 위한 블로그입니다. 운 좋게 미국에서 큰 회사들의 프로젝트에서 컬설턴트로 일하고 있어서 새로운 기술들을 접할 기회가 많이 있습니다. 미국의 IT 프로젝트에서 사용되는 툴들에 대해 많은 분들과 정보를 공유하고 싶습니다.
솔웅

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

글 보관함

카테고리


반응형

오늘 공부할 부분은 아래 페이지 입니다.

https://github.com/openai/openai-cookbook/blob/main/text_explanation_examples.md

 

GitHub - openai/openai-cookbook: Examples and guides for using the OpenAI API

Examples and guides for using the OpenAI API. Contribute to openai/openai-cookbook development by creating an account on GitHub.

github.com

Text explanation examples

Large language 모델은 긴 텍스트에서 정보를 추출하는데 유용합니다. 응용분야는 다음과 같습니다.

 

  • Answering questions about a piece of text, e.g.:
  • 텍스트 조각에 대한 질문들에 답하기, 예) 
    • Querying an knowledge base to help people look up things they don't know
    • 사람들이 모르는 것들을 찾는데 도움을 주는 지식 기반의 문의
    • Querying an unfamiliar document to understand what it contains
    • 어떤 내용인지 이해해야 되는 잘 모르는 문서에 대한 문의
    • Querying a document with structured questions in order to extract tags, classes, entities, etc.
    • 태그, 클래스, entity들을 추출하기 위한 구조화된 질문들이 있는 문서에 대한 문의
  • Summarizing text, e.g.
  • 문서 요약하기, 예 :
    • Summarizing long documents
    • 긴 문서 요약하기
    • Summarizing back-and-forth emails or message threads
    • 주고 받고 한 이메일이나 일련의 메세지를 요약하기
    • Summarizing detailed meeting notes with key points and next steps
    • 회의록을 키 포인트와 다음 단계에 대한 정보로 자세하게 요약하기
  • Classifying text, e.g.:
  • 문서 분류, 예. : 
    • Classifying customer feedback messages by topic or type
    • 고객들이 피드백 한 메세지를 주제와 유형별로 분류하기
    • Classifying documents by topic or type
    • 문서를 주제와 유형별로 분류하기
    • Classifying the tone or sentiment of text
    • 문서의 어조와 감정들을 분류하기
  • Extracting entities, e.g.:
  • Entity들을 추출하기, 예.: 
    • Extracting contact information from a customer message
    • 고객들의 메세지로부터 연락처 정보 추출하기
    • Extracting names of people or companies or products from a document
    • 문서에서 사람이나 회사 혹은 상품 이름 추출하기
    • Extracting things mentioned in customer reviews or feedback
    • 고객의 리뷰나 피드백들 속에서 언급된 것들 추출하기

다음은 위 예들에 대한 간단한 예제들 입니다.

 

Answering questions about a piece of text

아래는 텍스트 조각에 대한 질문에 대해 대답하도록 하는 프롬프트 예제 입니다.

Using the following text, answer the following question. If the answer is not contained within the text, say "I don't know."

Text:
"""
Oklo Mine (sometimes Oklo Reactor or Oklo Mines), located in Oklo, Gabon on the west coast of Central Africa, is believed to be the only natural nuclear fission reactor. Oklo consists of 16 sites at which self-sustaining nuclear fission reactions are thought to have taken place approximately 1.7 billion years ago, and ran for hundreds of thousands of years. It is estimated to have averaged under 100 kW of thermal power during that time.
"""

Question: How many natural fission reactors have ever been discovered?

Answer:

Output:

 

 One. Oklo Mine is believed to be the only natural nuclear fission reactor.

 

질문하려는 텍스트가 토큰 제한 (text-davinci-002/-003의 경우 ~4,000개 토큰 및 이전 모델의 경우 ~2,000개 토큰)보다 긴 경우 텍스트를 더 작은 조각으로 나누고 관련성에 따라 순위를 매길 수 있습니다. 그런 다음 가장 관련성이 있어 보이는 부분만 사용해서 질문하세요. 이는  Question_answering_using_embeddings.ipynb 에 설명 돼 있습니다.

 

https://coronasdk.tistory.com/1264

 

Openai cookbook - Embeddings - Text comparison examples - Question answering using embeddings

요즘은 open ai cook book 의 예제들을 살펴 보고 있습니다. 이 cookbook 페이지는 이곳입니다. https://github.com/openai/openai-cookbook GitHub - openai/openai-cookbook: Examples and guides for using the OpenAI API Examples and guides

coronasdk.tistory.com

 

학생들이 시험을 잘 보기 위해서 그동안 적었던 노트를 보듯이 GPT-3는 질문과 함께 텍스트를 주어주면 질문에 더 잘 답할 수 있습니다.

필기 노트가 없다면 GPT-3는 자신의 아주 긴 memory에 의존해야 합니다. (예. internal weights), 그렇게 되면 파편적인 대답 혹은 약간 뜬그룸 같은 대답을 하게 될 수 있습니다.

 

Summarization

아래는 문서를 요약하는 간단한 prompt 예제입니다.

Summarize the following text.

Text:
"""
Two independent experiments reported their results this morning at CERN, Europe's high-energy physics laboratory near Geneva in Switzerland. Both show convincing evidence of a new boson particle weighing around 125 gigaelectronvolts, which so far fits predictions of the Higgs previously made by theoretical physicists.

"As a layman I would say: 'I think we have it'. Would you agree?" Rolf-Dieter Heuer, CERN's director-general, asked the packed auditorium. The physicists assembled there burst into applause.
"""

Summary:

Output:

CERN's director-general asked a packed auditorium if they agreed that two independent experiments had found convincing evidence of a new boson particle that fits predictions of the Higgs, to which the physicists assembled there responded with applause.

 

이 예제 프롬프트에서 사용된 따옴표 3개 부호 (""") 는 특별한 것이 아닙니다. GPT-3는 <>, {}, 또는 ### 를 포함한 대부분의 구분 기호를 인식 할 수 있습니다. 긴 텍스트의 경우 이러한 구분 기호를 사용하는 것이 좋습니다. 텍스트의 한 섹션이 끝나고 다음 섹션이 시작되는 위치를 명확하게 구분하는데 도움이 됩니다.

 

Classification

텍스트를 분류하려는 경우 가장 좋은 방법은 클래스들을 미리 알고 있는지 여부에 따라 다릅니다.

클래스들을 이미 알고 있는 경우 Fine-tuned_classification.ipynb에서 설명한 것처럼 Fine-tuned 모델을 사용하여 분류하는 것이 가장 좋습니다.

클래스가 미리 알려지지 않은 경우 (예: 그것들이 사용자에 의해 세팅되거나 즉석해서 생성된 경우) 클래스들이 포함된 instruction을 제공해서 zero-shot classification을 사용할 수 있습니다. 혹은 어떤 클래스 레이블 (혹은 분류된 텍스트들)이 텍스트와 가장 유사한지를 보기 위한 임베딩을 사용해도 됩니다.  (Zero-shot_classification_with_embeddings.ipynb 에서 설명 됨)

 

Entity extraction

아래는 Entity 추출을 위한 예제 프롬프트 입니다.

From the text below, extract the following entities in the following format:
Companies: <comma-separated list of companies mentioned>
People & titles: <comma-separated list of people mentioned (with their titles or roles appended in parentheses)>

Text:
"""
In March 1981, United States v. AT&T came to trial under Assistant Attorney General William Baxter. AT&T chairman Charles L. Brown thought the company would be gutted. He realized that AT&T would lose and, in December 1981, resumed negotiations with the Justice Department. Reaching an agreement less than a month later, Brown agreed to divestiture—the best and only realistic alternative. AT&T's decision allowed it to retain its research and manufacturing arms. The decree, titled the Modification of Final Judgment, was an adjustment of the Consent Decree of 14 January 1956. Judge Harold H. Greene was given the authority over the modified decree....

In 1982, the U.S. government announced that AT&T would cease to exist as a monopolistic entity. On 1 January 1984, it was split into seven smaller regional companies, Bell South, Bell Atlantic, NYNEX, American Information Technologies, Southwestern Bell, US West, and Pacific Telesis, to handle regional phone services in the U.S. AT&T retains control of its long distance services, but was no longer protected from competition.
"""

Output:

Companies: AT&T, Bell South, Bell Atlantic, NYNEX, American Information Technologies, Southwestern Bell, US West, Pacific Telesis
People & titles: William Baxter (Assistant Attorney General), Charles L. Brown (AT&T chairman), Harold H. Greene (Judge)

 

 

반응형