한국어 추출 예제
LangExtract는 한국어, 일본어, 중국어를 포함한 비영어 언어에서 원활하게 작동합니다.
고려 사항
- 토큰화: LangExtract는 멀티바이트 문자를 자동으로 처리합니다.
- 프롬프트: 최상의 결과를 얻으려면 소스 텍스트와 동일한 언어로 프롬프트를 사용하세요.
코드 예제
python
import langextract as lx
# 1. 한국어 입력 텍스트
input_text = """
서울특별시는 대한민국의 수도이며, 인구는 약 950만 명입니다.
시장은 오세훈입니다.
"""
# 2. 한국어 프롬프트
prompt_description = """
다음 정보를 추출하세요:
- 도시명 (City name)
- 인구 (Population)
- 시장 (Mayor)
텍스트에서 정확하게 추출하고, 다른 표현으로 바꾸지 마세요.
"""
# 3. 예제 데이터 정의
examples = [
lx.data.ExampleData(
text="부산광역시는 인구 약 340만 명이며, 시장은 박형준입니다.",
extractions=[
lx.data.Extraction(extraction_class="city", extraction_text="부산광역시"),
lx.data.Extraction(extraction_class="population", extraction_text="약 340만 명"),
lx.data.Extraction(extraction_class="mayor", extraction_text="박형준")
]
)
]
# 4. 추출 실행
result = lx.extract(
text_or_documents=input_text,
prompt_description=prompt_description,
examples=examples,
model_id="gemini-2.5-flash",
)
# 5. 결과 표시
print("추출된 엔티티:")
for entity in result.extractions:
print(f"• {entity.extraction_class}: {entity.extraction_text}")예상 출력
추출된 엔티티:
• city: 서울특별시
• population: 약 950만 명
• mayor: 오세훈