메타데이터 추출

메타데이터 추출 (Metadata Extraction)

LLM을 사용해 문서에서 컨텍스트 정보를 추출해 검색과 언어 모델이 유사해 보이는 구절을 구분할 수 있게 돕는 기능이에요.

출처: 문서

본문

소개 (Introduction)

많은 경우, 특히 긴 문서에서는 텍스트 청크가 다른 유사한 텍스트 청크와 구분하는 데 필요한 컨텍스트가 부족할 수 있어요.

이를 해결하기 위해 LLM을 사용해 문서와 관련된 특정 컨텍스트 정보를 추출해서, 검색과 언어 모델이 비슷해 보이는 구절을 더 잘 구분할 수 있게 해요.

이를 예시 노트북으로 보여주고, 긴 문서 처리에서의 효과를 입증해요.

사용법

먼저, 순차적으로 처리될 피처 추출기(feature extractor) 목록을 받는 메타데이터 추출기를 정의해요. 그런 다음 이를 노드 파서에 넣어 각 노드에 추가 메타데이터를 더해요.

from llama_index.core.node_parser import SentenceSplitter
from llama_index.core.extractors import (
    SummaryExtractor,
    QuestionsAnsweredExtractor,
    TitleExtractor,
    KeywordExtractor,
)
from llama_index.extractors.entity import EntityExtractor


transformations = [
    SentenceSplitter(),
    TitleExtractor(nodes=5),
    QuestionsAnsweredExtractor(questions=3),
    SummaryExtractor(summaries=["prev", "self"]),
    KeywordExtractor(keywords=10),
    EntityExtractor(prediction_threshold=0.5),
]

그런 다음 입력 문서나 노드에 우리의 transformations을 실행할 수 있어요:

from llama_index.core.ingestion import IngestionPipeline


pipeline = IngestionPipeline(transformations=transformations)


nodes = pipeline.run(documents=documents)

추출된 메타데이터 예시:

{'page_label': '2',
 'file_name': '10k-132.pdf',
 'document_title': 'Uber Technologies, Inc. 2019 Annual Report: Revolutionizing Mobility and Logistics Across 69 Countries and 111 Million MAPCs with $65 Billion in Gross Bookings',
 'questions_this_excerpt_can_answer': '\n\n1. How many countries does Uber Technologies, Inc. operate in?\n2. What is the total number of MAPCs served by Uber Technologies, Inc.?\n3. How much gross bookings did Uber Technologies, Inc. generate in 2019?',
 'prev_section_summary': "\n\nThe 2019 Annual Report provides an overview of the key topics and entities that have been important to the organization over the past year. These include financial performance, operational highlights, customer satisfaction, employee engagement, and sustainability initiatives. It also provides an overview of the organization's strategic objectives and goals for the upcoming year.",
 'section_summary': '\nThis section discusses a global tech platform that serves multiple multi-trillion dollar markets with products leveraging core technology and infrastructure. It enables consumers and drivers to tap a button and get a ride or work. The platform has revolutionized personal mobility with ridesharing and is now leveraging its platform to redefine the massive meal delivery and logistics industries. The foundation of the platform is its massive network, leading technology, operational excellence, and product expertise.',
 'excerpt_keywords': '\nRidesharing, Mobility, Meal Delivery, Logistics, Network, Technology, Operational Excellence, Product Expertise, Point A, Point B'}

커스텀 추출기

제공된 추출기가 요구사항에 맞지 않으면 다음과 같이 커스텀 추출기를 정의할 수도 있어요:

from llama_index.core.extractors import BaseExtractor




class CustomExtractor(BaseExtractor):
    async def aextract(self, nodes) -> List[Dict]:
        metadata_list = [
            {
                "custom": node.metadata["document_title"]
                + "\n"
                + node.metadata["excerpt_keywords"]
            }
            for node in nodes
        ]
        return metadata_list

extractor.extract()는 내부적으로 aextract()를 자동으로 호출해서 sync와 async 진입점을 모두 제공해요.

더 고급 예시에서는 llm을 사용해 노드 내용과 기존 메타데이터에서 피처를 추출할 수도 있어요. 자세한 내용은 제공된 메타데이터 추출기의 소스 코드를 참고하세요.

모듈 (Modules)

아래에서 다양한 메타데이터 추출기에 대한 가이드와 튜토리얼을 찾을 수 있어요.

더 알아보기 (Learn more)