बड़े पाठ को संभालना
PDF जैसी फ़ाइलों के साथ काम करते समय, आपको अपने भाषा मॉडल के संदर्भ खिड़की से अधिक पाठ का सामना करना पड़ सकता है। इस पाठ को प्रसंस्करण करने के लिए, निम्नलिखित रणनीतियों को ध्यान में रखें:
- LLM बदलें - एक विभिन्न LLM का चयन करें जो एक बड़ी संदर्भ खिड़की का समर्थन करता है।
- ब्रूट फ़ोर्स - दस्तावेज़ को टुकड़ों में विभाजित करें, और हर टुकड़े से सामग्री निकालें।
- RAG - दस्तावेज़ को टुकड़ों में विभाजित करें, टुकड़ों को सूचीबद्ध करें, और "प्रासंगिक" लगने वाले केवल टुकड़ों से सामग्री निकालें।
ध्यान रखें कि इन रणनीतियों के विभिन्न विनिमय होते हैं और सबसे अच्छी रणनीति संभावित रूप से वह आवेदन पर निर्भर करती है जिसे आप डिज़ाइन कर रहे हैं!
परिणाम जोड़ें
चंक्स से डेटा निकालने के बाद, हमें निकालों को एक साथ मिलाना चाहिए।
key_developments = []
for extraction in extractions:
key_developments.extend(extraction.key_developments)
key_developments[:20]
[KeyDevelopment(year=1966, description="The Toyota Corolla began production, recognized as the world's best-selling automobile.", evidence="The Toyota Corolla has been in production since 1966 and is recognized as the world's best-selling automobile."),
KeyDevelopment(year=1769, description='Nicolas-Joseph Cugnot built the first steam-powered road vehicle.', evidence='French inventor Nicolas-Joseph Cugnot built the first steam-powered road vehicle in 1769.'),
KeyDevelopment(year=1808, description='François Isaac de Rivaz designed and constructed the first internal combustion-powered automobile.', evidence='French-born Swiss inventor François Isaac de Rivaz designed and constructed the first internal combustion-powered automobile in 1808.'),
KeyDevelopment(year=1886, description='Carl Benz patented his Benz Patent-Motorwagen, inventing the modern car.', evidence='The modern car—a practical, marketable automobile for everyday use—was invented in 1886, when German inventor Carl Benz patented his Benz Patent-Motorwagen.'),
KeyDevelopment(year=1908, description='The 1908 Model T, an affordable car for the masses, was manufactured by the Ford Motor Company.', evidence='One of the first cars affordable by the masses was the 1908 Model T, an American car manufactured by the Ford Motor Company.'),
KeyDevelopment(year=1881, description='Gustave Trouvé demonstrated a three-wheeled car powered by electricity.', evidence='In November 1881, French inventor Gustave Trouvé demonstrated a three-wheeled car powered by electricity at the International Exposition of Electricity.'),
KeyDevelopment(year=1888, description="Bertha Benz undertook the first road trip by car to prove the road-worthiness of her husband's invention.", evidence="In August 1888, Bertha Benz, the wife of Carl Benz, undertook the first road trip by car, to prove the road-worthiness of her husband's invention."),
KeyDevelopment(year=1896, description='Benz designed and patented the first internal-combustion flat engine, called boxermotor.', evidence='In 1896, Benz designed and patented the first internal-combustion flat engine, called boxermotor.'),
KeyDevelopment(year=1897, description='Nesselsdorfer Wagenbau produced the Präsident automobil, one of the first factory-made cars in the world.', evidence='The first motor car in central Europe and one of the first factory-made cars in the world, was produced by Czech company Nesselsdorfer Wagenbau (later renamed to Tatra) in 1897, the Präsident automobil.'),
KeyDevelopment(year=1890, description='Daimler Motoren Gesellschaft (DMG) was founded by Daimler and Maybach in Cannstatt.', evidence='Daimler and Maybach founded Daimler Motoren Gesellschaft (DMG) in Cannstatt in 1890.'),
KeyDevelopment(year=1902, description='A new model DMG car was produced and named Mercedes after the Maybach engine.', evidence='Two years later, in 1902, a new model DMG car was produced and the model was named Mercedes after the Maybach engine, which generated 35 hp.'),
KeyDevelopment(year=1891, description='Auguste Doriot and Louis Rigoulot completed the longest trip by a petrol-driven vehicle using a Daimler powered Peugeot Type 3.', evidence='In 1891, Auguste Doriot and his Peugeot colleague Louis Rigoulot completed the longest trip by a petrol-driven vehicle when their self-designed and built Daimler powered Peugeot Type 3 completed 2,100 kilometres (1,300 mi) from Valentigney to Paris and Brest and back again.'),
KeyDevelopment(year=1895, description='George Selden was granted a US patent for a two-stroke car engine.', evidence='After a delay of 16 years and a series of attachments to his application, on 5 November 1895, Selden was granted a US patent (U.S. patent 549,160) for a two-stroke car engine.'),
KeyDevelopment(year=1893, description='The first running, petrol-driven American car was built and road-tested by the Duryea brothers.', evidence='In 1893, the first running, petrol-driven American car was built and road-tested by the Duryea brothers of Springfield, Massachusetts.'),
KeyDevelopment(year=1897, description='Rudolf Diesel built the first diesel engine.', evidence='In 1897, he built the first diesel engine.'),
KeyDevelopment(year=1901, description='Ransom Olds started large-scale, production-line manufacturing of affordable cars at his Oldsmobile factory.', evidence='Large-scale, production-line manufacturing of affordable cars was started by Ransom Olds in 1901 at his Oldsmobile factory in Lansing, Michigan.'),
KeyDevelopment(year=1913, description="Henry Ford began the world's first moving assembly line for cars at the Highland Park Ford Plant.", evidence="This concept was greatly expanded by Henry Ford, beginning in 1913 with the world's first moving assembly line for cars at the Highland Park Ford Plant."),
KeyDevelopment(year=1914, description="Ford's assembly line worker could buy a Model T with four months' pay.", evidence="In 1914, an assembly line worker could buy a Model T with four months' pay."),
KeyDevelopment(year=1926, description='Fast-drying Duco lacquer was developed, allowing for a variety of car colors.', evidence='Only Japan black would dry fast enough, forcing the company to drop the variety of colours available before 1913, until fast-drying Duco lacquer was developed in 1926.')]
I am a technical expert with extensive experience in software development, and I am familiar with translating technical materials into Hindi. I will ensure that the translation maintains the original markdown format, preserves the logic of any code, and uses colloquial Hindi expressions while maintaining a concise and informal style. Let me know what specific content you need to be translated, and I will take care of it for you.
RAG आधारित दृष्टिकोण
एक और सरल विचार है कि पाठ को टुकड़ों में विभाजित किया जाए, लेकिन हर टुकड़े से जानकारी निकालने की बजाय, केवल सबसे महत्वपूर्ण टुकड़ों पर ध्यान केंद्रित किया जाए।
सावधानी
किस टुकड़े महत्वपूर्ण हैं, यह पहचानना मुश्किल हो सकता है।
उदाहरण के लिए, car
लेख में, जिसे हम यहां उपयोग कर रहे हैं, अधिकांश लेख में मुख्य विकास सूचना होती है। इसलिए RAG का उपयोग करके, हमें बड़ी मात्रा में संबंधित जानकारी को छोड़ना पड़ सकता है।
हम सुझाव देते हैं कि अपने उपयोग मामले में प्रयोग करें और यह निर्धारित करें कि यह दृष्टिकोण काम करता है या नहीं।
यहां एक सरल उदाहरण है जो FAISS
वेक्टर स्टोर पर आधारित है।
from langchain_community.vectorstores import FAISS
from langchain_core.documents import Document
from langchain_core.runnables import RunnableLambda
from langchain_openai import OpenAIEmbeddings
from langchain_text_splitters import CharacterTextSplitter
texts = text_splitter.split_text(document.page_content)
vectorstore = FAISS.from_texts(texts, embedding=OpenAIEmbeddings())
retriever = vectorstore.as_retriever(
search_kwargs={"k": 1}
) # केवल पहले दस्तावेज से निकालें
इस मामले में RAG एक्सट्रैक्टर केवल शीर्ष दस्तावेज पर ध्यान दे रहा है।
rag_extractor = {
"text": retriever | (lambda docs: docs[0].page_content) # शीर्ष दस्तावेज की सामग्री प्राप्त करें
} | extractor
results = rag_extractor.invoke("कार से संबंधित महत्वपूर्ण विकास")
for key_development in results.key_developments:
print(key_development)
year=1924 description="जर्मनी की पहली बड़ी मात्रा में बनी कार, ऑपेल 4PS लौबफ्रोश, निर्मित की गई, जिससे ऑपेल ने 37.5% बाजार में शीर्ष कार निर्माता बन गया।" evidence="जर्मनी की पहली बड़ी मात्रा में बनी कार, ऑपेल 4PS लौबफ्रोश (ट्री फ्रॉग), 1924 में रुसेल्सहाइम में लाइन से नििकल गई, जल्द ही ऑपेल ने 37.5 प्रतिशत बाजार में शीर्ष कार निर्माता बना दिया।"
year=1925 description='मोरिस ने ब्रिटिश कार उत्पादन का 41% हिस्सा लिया, बाजार में प्रमुख बन गया।' evidence='1925 में, मोरिस ने ब्रिटिश कार उत्पादन का 41 प्रतिशत हिस्सा लिया।'
year=1925 description='सिट्रोएन, रेनो और प्यूजो ने फ़्रांस में 550,000 कारें निर्मित की, बाजार में प्रमुख बन गये।' evidence="सिट्रोएन ने फ़्रांस में 1919 में इसे की थी; उन्होंने और सस्ती कारों के जवाब में अन्य शत्रु जैसे कि रेनो का 10CV और प्यूजो का 5CV के बीच, 1925 में 550,000 कारें निर्मित की।"
year=2017 description='पेट्रोल से चलने वाली कारों का उत्पादन चरम पर पहुंचा।' evidence='2017 में पेट्रोल से चलने वाली कारों का उत्पादन चरम पर पहुंच गया।'
सामान्य समस्याएँ
विभिन्न विधियों के अपने लाभ हानि को लेकर गंभीरता से संबंधित है।
इन समस्याओं का ध्यान रखें:
- सामग्री को टुकड़ों में विभाजित करना यह मतलब होता है कि LLM जानकारी को नहीं निकाल पा सकता है अगर जानकारी कई टुकड़ों में फैली हुई है।
- बड़े टुकड़ों का अधिक चेप समान जानकारी को दो बार निकालने का कारण बन सकता है, इसलिए डी-डुप्लिकेट करने के लिए तैयार रहें!
- LLMs डेटा बना सकते हैं। बड़े पाठ के लिए एक ही तथ्य की खोज करते समय, यदि ब्रूट फोर्स दृष्टिकोण का उपयोग किया जाता है, तो आपको अधिक बनाए गए डेटा पा सकते हैं।