Langchain Seyir Defterim 🦜🔗

Kardel Rüveyda ÇETİN
25 min readApr 10, 2024

Bu yazı kapsamında sizlerle Tirendaz Akademi’den almış olduğum Langchain ile ilgili bir kurstan çıkardığım notları paylaşacağım. Ayrıca bu akademinin kurslarına bayılıyorum. Sizin de benim gibi yapay zeka alanına ilginiz varsa ve kendinizi geliştirmek istiyorsanız başlangıç seviyesinden ileri seviyeye doğru birçok kurs var. Tavsiye ederim. Umarım çıkarmış olduğum bu notlar da herkese faydalı olur . Haydi başlayalım ! :)

Generative AI Kavramı ve Langchain

🦜🔗 Generative AI, dil modellerini kullanarak chatbot gibi uygulamalar geliştirmenin son zamanlarda oldukça popüler hale geldiği bir alandır. Bu trendin bir parçası olarak, Langchain adlı bir framework ortaya çıktı. Langchain, büyük dil modellerini kullanarak uygulamalar geliştirmek için tasarlanmıştır ve son bir yıl içinde hızla popülerlik kazanmıştır. Yakın zamanda, Langchain’in yeni bir sürümü olan Version 0.1 duyurulmuştur.

🦜🔗Önceki versiyonda, tüm modüller Langchain kütüphanesi içinde bulunuyordu. Ancak, yeni versiyonla birlikte Langchain üç ana parçaya ayrıldı: Langchain Core, Langchain Community ve Langchain’in kendisi. Langchain Core, temel fonksiyonları, arabirimleri ve soyutlamaları içerir ve daha kararlı bir yapı sunar. Langchain Core içinde, “chainler”, “retriveal stratejileri” ve “agentlar” gibi özellikler bulunur.

👉 Langchain Community, üçüncü parti entegrasyonlarını içerir. Şu anda, Langchain ile uyumlu olan 700'den fazla kütüphane bulunmaktadır. Bu entegrasyonlar arasında, OpenAI ve Google önemli iş ortaklarının kütüphaneleri de bulunmaktadır.

👉 Langchain kullanıcılarının uygulamalarını hata ayıklamak için “LangSmith” adlı bir aracı kullanabileceğini belirtmek önemlidir. Bu araç, adım adım hataları inceleme imkanı sunar.

👉 Ayrıca, LLM uygulamalarınızı “LangServe” ile dağıtabilirsiniz. Bu modül, büyük dil modellerini uygulamanızın bir parçası olarak görselleştirmenize olanak tanır ve uygulamanızın performansını test etmenizi sağlar.

Kütüphanelerin Yüklenmesi

👉İlk olarak, projeniz için gerekli olan kütüphaneleri belirleyebilirsiniz. Ben bu örnekler kapsamında aşağıdaki kütüphaneleri kullandım.

  • langchain (sürüm: 0.1.13)
  • langchain-core (sürüm: 0.1.33)
  • langchain-openai (sürüm: 0.1.1)
  • python-dotenv (sürüm: 1.0.1)
  • beautifulsoup4 (sürüm: 4.12.3)
  • faiss-cpu (sürüm: 1.8.0)
  • huggingface_hub (sürüm: 0.21.4)

👉Ardından, bu kütüphaneleri tek tek belirlediğiniz sürümleriyle birlikte requirements.txt adında bir dosyada listeleyebilirsiniz.

👉Sonrasında, projenizde bu kütüphaneleri kullanmak isteyen başka bir kişi veya siz projeyi başka bir ortamda çalıştırmak istediğinizde, requirements.txt dosyasını kullanarak bu kütüphaneleri yüklemek için bir komut oluşturabilirsiniz. Oluşturduğunuz komut, pip paket yöneticisini kullanarak requirements.txt dosyasındaki kütüphaneleri yükler.

!pip install -r requirements.txt

👉Bu komutu çalıştırdığınızda, belirttiğiniz kütüphaneler ve sürümleri otomatik olarak yüklenir.

Bu şekilde, projenizde kullanılan kütüphaneleri başka kullanıcılar veya farklı ortamlar için kolayca yükleyebilirsiniz. Bu, projenizi başkalarıyla paylaşırken veya farklı bilgisayarlarda çalıştırırken oldukça kullanışlı bir yöntemdir.

Open API Key’in Oluşturulması

OpenAI API anahtarının oluşturulması çok kolaydır. İlk adım olarak, OpenAI web sitesine giderek bir hesap oluşturmalısınız. Hesabınızı oluşturduktan sonra, API anahtarınızı oluşturmak için gerekli adımları takip edebilirsiniz. Modelinizi kullanmak için, genellikle ChatOpenAI sınıfını kullanırız ve bu sınıfta genellikle GPT-3.5 Turbo gibi önceden tanımlanmış bir model seçeriz. Bu modeli seçtikten sonra, sonuçları belirlemek için “Temperature” parametresini ekleyebiliriz. Temperature parametresi, sonuçların rastgeleliğini kontrol eder. Değeri 0'a yaklaştıkça, sonuçlar daha kararlı hale gelir ve belirli bir konuya odaklanır. Ancak, değeri 1'e yaklaştıkça, sonuçlar daha rastgele ve çeşitli olur. Genellikle, varsayılan değeri olan 0.7 kullanılır, çünkü bu değer genellikle istenen dengeyi sağlar: belirli bir konuya odaklanmak ve aynı zamanda çeşitli sonuçlar elde etmek. Bu yöntemi kullanarak, OpenAI API’sini hızlı ve verimli bir şekilde kullanabilir ve istediğiniz sonuçları elde edebilirsiniz.

Aşağıdaki kodda ChatOpenAI sınıfı, OpenAI API'sini kullanarak metin tabanlı bir sohbet botu geliştirmeyi sağlar. Bu sınıfı kullanarak, çeşitli metin tabanlı görevler için yapay zeka modelini kullanabilirsiniz. Kod, ChatOpenAI sınıfının bir örneğini llm adında bir değişkene atıyor. Bu örneği oluştururken, model_name parametresi aracılığıyla kullanılacak modelin belirtilmesi gerekiyor. Burada, "gpt-3.5 turbo" adlı bir model seçilmiş. Bu kodun amacı, OpenAI’nin sağladığı GPT-3.5 Turbo adlı yapay zeka modelini kullanarak metin tabanlı bir sohbet botu oluşturmak ve bu amaçla ChatOpenAI sınıfının bir örneğini oluşturmaktır.

from langchain_openai import ChatOpenAI

llm = ChatOpenAI(
model_name = "gpt-3.5 turbo",
)

Aşağıdaki kodda ise, llm adlı ChatOpenAI sınıfının bir örneği üzerinden invoke() metodu aracılığıyla bir metin sorgusunun yapılmasını sağlar. İlk olarak, text adında bir değişkene "Who is Albert Einstein?" şeklinde bir metin atanır. Bu metin, yapay zeka modeline sorulacak bir soruyu temsil eder. Ardından, invoke() metodu çağrılarak text değişkenindeki metin sorgusu model üzerinde çalıştırılır ve modelin yanıtı response adlı bir değişkene atanır. Son olarak, response değişkeni çağrıldığında, yapay zeka modelinden gelen cevap alınır ve bu cevap kullanıcıya sunulur veya işlenir.

text = "Who is Albert Einstein?"
response = llm.invoke(text)
response
AIMessage(content='Albert Einstein was a German-born physicist who developed the theory of relativity, one of the two pillars of modern physics (alongside quantum mechanics). He is best known for his mass-energy equivalence formula E=mc^2 and his groundbreaking work on the photoelectric effect, for which he was awarded the Nobel Prize in Physics in 1921. Einstein is considered one of the greatest scientists of all time and his work has had a profound impact on the field of physics and our understanding of the universe.', response_metadata={'token_usage': {'completion_tokens': 100, 'prompt_tokens': 12, 'total_tokens': 112}, 'model_name': 'gpt-3.5-turbo', 'system_fingerprint': 'fp_3bc1b5746c', 'finish_reason': 'stop', 'logprobs': None})
Photo by My Foto Canva on Unsplash

Hugging Face Üzerinden Açık Kaynak bir modeli kullanmak

Aşağıdaki örnek; Hugging Face Hub üzerinden bir dil modeli yüklemeyi ve bu modeli kullanarak bir HuggingFaceHub örneği oluşturmayı sağlar.

İlk olarak, langchain_community modülünden HuggingFaceHub sınıfı import edilir. Bu sınıf, Hugging Face Hub'dan dil modellerini yüklemek ve kullanmak için kullanılır. Ardından, os modülü import edilir. Bu modül, işletim sistemi ile ilgili işlemleri gerçekleştirmek için kullanılır. Daha sonra, HuggingFaceHub sınıfının bir örneği hf adlı bir değişkene atanır. Bu örnek oluşturulurken şu parametreler kullanılır:

  • repo_id: Yüklenmek istenen dil modelinin Hugging Face Hub'daki depo kimliği belirtilir. Bu örnekte, "google/flan-t5-large" adlı bir dil modeli seçilmiştir.
  • model_kwargs: Yüklenen dil modelinin parametreleri belirtilir. Bu örnekte, "temperature" ve "max_length" gibi parametreler belirtilmiştir.
  • huggingfacehub_api_token: Hugging Face Hub API'sine erişmek için gerekli olan API anahtarı belirtilir. Bu örnekte, bu anahtar bir ortam değişkeninden alınmaktadır: os.environ["HUGGINGFACEHUB_API_TOKEN"].

Bu kod bloğu, Hugging Face Hub’dan belirtilen dil modelini yükleyerek, belirtilen parametrelerle bir HuggingFaceHub örneği oluşturur. Bu örnek daha sonra kullanılarak dil modeli üzerinde çeşitli işlemler gerçekleştirilebilir.

from langchain_community.llms import HuggingFaceHub
import os

hf = HuggingFaceHub(repo_id = "google/flan-t5-large",model_kwargs={"temperature":0.7,"max_length":100},
huggingfacehub_api_token=os.environ["HUGGINGFACEHUB_API_TOKEN"])
output = hf.invoke(text);
print(output)
physicist

Chat Model vs Hugging Face Model

Girdi ve çıktı şekilleri büyük dil modelleri string metin alır ve metin üretir. ChatModelleri Mesaj listesini alır çıktı olarak bir mesaj verir.

İlk olarak, “recommend” adlı bir metin sorgusu tanımlanmıştır. Bu sorgu, bir film önerisi talebini içerir: “Bilim kurgu hakkında bir film önerebilir misiniz?”

recommend= "Can you recommend a film about science fiction?"

Daha sonra, langchain_core.messages modülünden HumanMessage sınıfı import edilmiştir. Bu sınıf, insan mesajlarını temsil eder ve content parametresi ile mesaj içeriğini alır. messages adlı bir liste oluşturulmuş ve içine "recommend" adlı metin sorgusu eklenmiştir.

from langchain_core.messages import HumanMessage
messages = [HumanMessage(content= recommend)]

Ardından, langchain_openai modülünden ChatOpenAI ve OpenAI sınıfları import edilmiştir. OpenAI sınıfı, genel OpenAI API'sine erişim sağlar. ChatOpenAI sınıfı ise, OpenAI API'sini kullanarak sohbet botu işlevselliği sağlar. OpenAI sınıfından bir örnek oluşturulmuş ve llm adlı bir değişkene atanmıştır. Daha sonra, ChatOpenAI sınıfından da bir örnek oluşturulmuş ve chat_model adlı bir değişkene atanmıştır.

from langchain_openai import ChatOpenAI,OpenAI
llm = OpenAI()
chat_model = ChatOpenAI()

Son olarak, llm.invoke(recommend) ve chat_model.invoke(recommend) satırlarıyla, her iki model de "recommend" adlı metin sorgusunu işlemek için çağrılmıştır.

llm.invoke(recommend)
\n\nOne film that comes to mind is "Blade Runner" (1982). It is a classic science fiction film directed by Ridley Scott, set in a dystopian future where genetically engineered replicants are used as laborers on Earth\'s off-world colonies. The film explores themes of artificial intelligence, identity, and the blurred lines between humans and machines. It also features stunning visuals and a thought-provoking storyline that has become a staple in the science fiction genre.
chat_model.invoke(recommend)
AIMessage(content='Sure! I recommend the film "Blade Runner 2049" directed by Denis Villeneuve. This film is a visually stunning and thought-provoking science fiction movie that explores themes of artificial intelligence, identity, and the nature of humanity. It is a sequel to the classic film "Blade Runner" and has received critical acclaim for its stunning cinematography, compelling story, and powerful performances from its cast. I think you will enjoy it if you are a fan of science fiction films.', response_metadata={'token_usage': {'completion_tokens': 100, 'prompt_tokens': 16, 'total_tokens': 116}, 'model_name': 'gpt-3.5-turbo', 'system_fingerprint': 'fp_b28b39ffa8', 'finish_reason': 'stop', 'logprobs': None})

Yani, aslında kod bloğu, iki farklı yapay zeka modelini kullanarak bir metin sorgusunu işlemeye çalışmaktadır.

Promptlarla Çalışmak

Büyük dil modelleri kullanırken, doğru promptlar önemlidir. İyi bir prompt, modelin verdiği cevabın kalitesini belirler.

  1. İlk olarak, langchain modülünden PromptTemplate sınıfı import edilir. Bu sınıf, promptlar oluşturmak ve formatlamak için kullanılır.
  2. Ardından, PromptTemplate.from_template() yöntemi kullanılarak bir prompt oluşturulur. Bu yöntem, belirli bir metin şablonundan ("Can you recommend a film about {topic}?") bir prompt oluşturur. Burada, {topic} yer tutucusu, sonradan değiştirilecek olan bir değişkeni temsil eder.
  3. prompt.format() yöntemi, oluşturulan promptu belirli bir değerle (bu durumda "Romantic Comedy" olarak belirlenmiş) doldurur. Yani, {topic} yer tutucusu "Romantic Comedy" ile değiştirilir.
  4. Sonuç olarak, prompt.format() yöntemi tarafından oluşturulan metin olan "Can you recommend a film about Romantic Comedy?" çıktı olarak döndürülür. Bu, belirli bir konuyla ilgili bir film önerisi talebini içeren bir prompttur.
from langchain.prompts import PromptTemplate

prompt = PromptTemplate.from_template("Can you recommend a film about {topic}?")
prompt.format(topic="Romantic Comedy")
Can you recommend a film about Romantic Comedy

Aşağıdaki kod, Langchain’in bir bileşeni olan OpenAI API’sini kullanarak metin tabanlı sohbet botları oluşturmayı sağlayan ChatOpenAI sınıfından bir örnek oluşturur.

  1. İlk olarak, langchain_openai modülünden ChatOpenAI sınıfı import edilir. Bu sınıf, metin tabanlı sohbet botları oluşturmak için OpenAI API'sini kullanır.
  2. Ardından, ChatOpenAI() çağrısı ile ChatOpenAI sınıfından bir örnek oluşturulur. Bu örnek, llm adlı bir değişkene atanır. Bu adım, ChatOpenAI sınıfının özelliklerini ve işlevselliğini kullanabilmek için bir arayüz sağlar.

Bu kod bloğu, OpenAI API’sini kullanarak metin tabanlı sohbet botları oluşturmayı sağlayan ChatOpenAI sınıfından bir örnek oluşturur. Bu örnek daha sonra çeşitli metin sorgularını işlemek için kullanılabilir.

from langchain_openai import ChatOpenAI

llm = ChatOpenAI()

Aşağıdaki alanda amaç bir zincirleme işlemi gerçekleştirerek bir metin sorgusunu işler. İşlem, belirli bir prompt ve bir yapay zeka modeli arasında gerçekleşir.

  1. chain = prompt | llm: Bu satırda, prompt adlı bir prompt ve llm adlı bir yapay zeka modeli bir araya getirilerek bir zincir oluşturulur. | operatörü, zincirleme işlemi için kullanılır ve prompt'un sonucu llm'e iletilir.
  2. chain.invoke({"topic":"Romantic Comedy"}): Bu satırda, chain adlı oluşturulan zincir çağrılır ve {"topic":"Romantic Comedy"} adlı bir parametre ile çağrılır. Bu parametre, prompt içindeki değişkenlerin (bu durumda {topic}) değerlerini belirlemek için kullanılır. Zincirin sonucu, belirtilen parametrelerle işlenmiş metin sorgusunun cevabıdır.
chain = prompt | llm
chain.invoke({"topic":"Romantic Comedy"})
AIMessage(content='One classic romantic comedy film that I would recommend is "When Harry Met Sally." This iconic movie follows the unlikely friendship and eventual romantic relationship between Harry Burns (Billy Crystal) and Sally Albright (Meg Ryan) as they navigate the ups and downs of love and friendship. With witty dialogue, charming performances, and a memorable soundtrack, "When Harry Met Sally" is a must-watch for fans of the romantic comedy genre.', response_metadata={'token_usage': {'completion_tokens': 84, 'prompt_tokens': 15, 'total_tokens': 99}, 'model_name': 'gpt-3.5-turbo', 'system_fingerprint': 'fp_3bc1b5746c', 'finish_reason': 'stop', 'logprobs': None})

Output Parser ile zincir sonucunu değiştirebilirsiniz!

Aşağıdaki kod ile, langchain_core adlı bir kütüphaneden StrOutputParser sınıfını içe aktarır ve bu sınıfı output_parser adlı bir değişkene atar. Bu sınıf, muhtemelen bir tür metin çıktısını analiz etmek ve işlemek için tasarlanmış bir çıktı ayrıştırıcıdır. StrOutputParser sınıfının tam olarak ne yaptığını bilmek için, langchain_core kütüphanesinin belgelerine başvurmanız veya kütüphanenin kodunu incelemeniz gerekebilir. Ancak genel olarak, adından da anlaşılacağı gibi, bir metin çıktısını analiz edip işleyen bir çıktı ayrıştırıcı olduğunu söyleyebilirim. Bu çıktı ayrıştırıcı, muhtemelen metin tabanlı verileri işlemek için kullanılır ve gerekirse çıktıyı uygun bir veri yapısına dönüştürür.

from langchain_core.output_parsers import StrOutputParser

output_parser = StrOutputParser()
chain = prompt | llm | output_parser
chain.invoke({"topic":"Romantic Comedy"})
One popular romantic comedy film that I would recommend is "When Harry Met Sally." This film follows the story of Harry and Sally, who meet in college and then reconnect several times over the years. The film explores the question of whether men and women can truly be friends without any romantic feelings getting in the way. It\'s a classic romantic comedy with great chemistry between the two leads, played by Billy Crystal and Meg Ryan.

Birden fazla prompt gönderme işlemi

Bu kod, langchain adlı bir modülden ChatPromptTemplate adlı bir sınıfı içe aktarır. Ardından, "You are a helpful assistant that translates {input_language} to {output_language}." şeklinde bir metin şablonu tanımlar ve bu şablonu template adlı bir değişkene atar. Daha sonra, "human_template" adlı bir diğer değişken tanımlanır ve bu değişken "text" adlı bir değişkeni içerir.

from langchain.prompts.chat import ChatPromptTemplate
template = "You are a helpful assistant that translates {input_language} to {output_language}."

human_template = "{text}";

ChatPromptTemplate sınıfından bir örnek oluşturur ve from_messages yöntemini kullanarak bir dizi mesajdan bu örneği oluşturur.

Verilen mesajlar, bir çift olarak sağlanır. İlk öğe, mesajın kimden geldiğini belirtir ("system" veya "human"), ikinci öğe ise mesajın içeriğini içerir. Önceki adımda tanımladığımız template ve human_template değişkenleri bu mesajlara verilir.

Bu işlem, belirli bir sohbet şablonu oluşturmak için kullanılır. Mesajlar, sistem tarafından oluşturulmuş (“system”) veya insan tarafından oluşturulmuş (“human”) olabilir. Bu mesajlar, sohbet sistemine örnek mesajlar sağlayarak, sohbet modelinin eğitilmesine yardımcı olabilir. Bu tür bir veri, doğal dil işleme (NLP) sistemlerinin eğitiminde sıklıkla kullanılır.

chat_prompt = ChatPromptTemplate.from_messages([
("system",template),
("human",human_template)
])

Son olarak bir dizi işlevsel bileşeni birbirine bağlayan bir zinciri oluşturmak amaçlanır. Zincirde üç bileşen bulunmaktadır:

  1. chat_prompt: Giriş metni ve dillerin belirtildiği çeviri işlevini gerçekleştiren bir bileşen.
  2. llm: Büyük olasılıkla bir dil modelini veya dil işleme bileşenini temsil eder.
  3. output_parser: Çıktıyı işleyen bir bileşen olabilir, muhtemelen çıktıdaki metni düzenler veya işler.

chain.invoke() çağrısı, bu zinciri çalıştırmak için kullanılır.

  • "input_language": Giriş metnin dilini belirtir, bu durumda İngilizce.
  • "output_language": Çıkış metnin dilini belirtir, bu durumda Türkçe.
  • "text": Çevrilecek metni belirtir, bu durumda "I love food" (Yani "Yemekleri seviyorum").

Bu kod, “I love food” metnini İngilizceden Türkçeye çevirmek için bir zincirdeki işlevleri kullanır ve çıktıyı işler.

chain = chat_prompt | llm | output_parser

chain.invoke({
"input_language" : "English",
"output_language" : "Turkish",
"text" : "I love food"
})
Ben yemekleri seviyorum.

Chainlerle Birlikte Çalışmak!

Chainlerle birlikte çalışmaya farklı bir örnek üzerinden devam edelim. Ne kadar pratik yaparsak o kadar iyi bir şekilde anlarız diye düşünüyorum. :)

Aşağıdaki kod örneği, bir dil zinciri oluşturmayı amaçlar. İşlevlerin her biri farklı dillere özgü görevler gerçekleştirebilir.

  1. from langchain.prompts.chat import ChatPromptTemplate: Bu satır, bir dil zinciri için sohbet şablonunu içeren bir modülü içeri aktarır. Bu şablon, sohbet konularını yönlendirmek için kullanılabilir.
  2. promptChain = PromptTemplate.from_template("Can you say name film's topic {name}?"): Bu satır, belirli bir sohbet şablonunu temel alan bir dil zinciri oluşturur. Belirtilen şablonda, belirli bir film hakkında konuşmak için kullanılacak bir ifade bulunuyor. Örneğin, "Can you say name film's topic {name}?" ifadesi, bir film hakkında konuşurken filmin adını belirtilen yere yerleştirecektir.
  3. model = ChatOpenAI(): Bu satır, bir ChatGPT modelini yükler veya başlatır. ChatGPT modeli, doğal dil işleme ve sohbet etme yeteneklerine sahip bir yapay zeka modelidir. Bu model, belirli bir dil zinciri içindeki diyalogları yönlendirmek için kullanılabilir.
from langchain.prompts.chat import ChatPromptTemplate
promptChain = PromptTemplate.from_template("Can you say name film's topic {name}?")

model = ChatOpenAI()

Aşağıdaki kod, dil zincirine bir çıktı analizcisi (output parser) ekler.

  1. from langchain_core.output_parsers import StrOutputParser: Bu satır, çıktıları işlemek için bir çıktı analizcisi olan StrOutputParser sınıfını içeri aktarır.
  2. output_parser = StrOutputParser(): Bu satır, StrOutputParser sınıfından bir örnek oluşturur. Bu, çıktıları düzenlemek, işlemek veya analiz etmek için kullanılabilir.
  3. chain = promptChain | model | output_parser: Bu satırda, bir dil zinciri oluşturulmaktadır. Önceki kodda promptChain ve model oluşturulmuştu. Bu satırda, promptChain ile başlayarak bir zincir oluşturuluyor. Ardından bu zincire bir dil modeli (model) ve bir çıktı analizcisi (output_parser) ekleniyor. Zincirdeki her bileşen, girdi olarak birbirine geçirilen çıktıları alır ve sonuçları işler. Bu şekilde, zincirdeki her bir bileşen önceki bileşenin çıktısını işler ve sonuçları zincirin sonraki bileşenine aktarır. Bu zincirin sonuçları çıktı analizcisi (output_parser) tarafından işlenebilir veya düzenlenebilir.
from langchain_core.output_parsers import StrOutputParser

output_parser = StrOutputParser()
chain = promptChain|model|output_parser

chain.invoke() yöntemi, zincirdeki tüm bileşenleri sırayla çalıştırır ve girdi olarak verilen parametrelere göre sonuç üretir.

chain.invoke({"name":"Angelina Jolie"})
Sure! One film topic that Angelina Jolie has been involved in is "Maleficent," where she plays the iconic Disney villain from "Sleeping Beauty."

RAG (Retrieval-Augmented Generation)

RAG (Retrieval-Augmented Generation), büyük dil modellerinin normalde belirli bir tarihe kadar olan büyük veri setleriyle eğitildiği bir yöntemdir. Ancak bu modeller, güncel bilgileri sağlama ve belirli bir alandaki spesifik bilgileri verme konusunda zorlanabilirler. Modelin daha iyi bir şekilde soruları yanıtlayabilmesi için ek bilgilere ihtiyaç duyulabilir ve bu ihtiyacı Retriever (Veri Kurtarıcı) tekniğiyle karşılayabiliriz. Modeli bu verilere erişebileceği kaynaklarla besleyebiliriz, örneğin PDF dosyaları, veritabanları veya web siteleri gibi. Bu şekilde, modelin daha kapsamlı ve güncel bilgilere erişmesi sağlanabilir, sorulara daha doğru ve detaylı yanıtlar sunabilir.

Retrieval Tekniği

Bu yöntemi kullanarak modeli beslemek için mevcut verilerinizden faydalanabilirsiniz. Bu şekilde, modele verileri sunarak belirli bir alanda uzmanlaşmasını sağlayabilirsiniz. Bu verileri PDF dosyaları, veritabanları veya web sitelerinden alabilirsiniz. Örneğin, verileri bir blog sayfasından çekebiliriz. Verileri saklamak için vektör tabanlı bir veritabanı kullanmayı planlıyoruz. Bu vektör tabanından modelin bilgileri almasını sağlayacağız. Veri setindeki bilgileri dizinlemek için WebBaseLoader gibi bir araç kullanabiliriz. Ancak bu işlem için Beautiful Soup kütüphanesini indirmeniz gerekmektedir.

Bu kod, langchain_community modülünden WebBaseLoader sınıfını kullanarak bir web sayfasından belge yüklemeyi gerçekleştiriyor.

  1. from langchain_community.document_loaders import WebBaseLoader: Bu satır, belirli bir web sayfasından belge yüklemek için WebBaseLoader sınıfını içeri aktarır.
  2. loader = WebBaseLoader("https://m.imdb.com/chart/top/"): Bu satırda, yüklenecek web sayfasının URL'sini belirten bir WebBaseLoader örneği oluşturulur. Bu örneğe "https://m.imdb.com/chart/top/" URL'si verilmiş, bu da IMDb'nin en iyi film listesi gibi bir web sayfasını işaret etmektedir.
  3. docs = loader.load(): Bu satır, oluşturulan loader örneği aracılığıyla belgenin yüklenmesini gerçekleştirir. Yüklenen belge, docs değişkenine atanır.
from langchain_community.document_loaders import WebBaseLoader 

loader = WebBaseLoader("https://m.imdb.com/chart/top/")

docs = loader.load()
[Document(page_content="IMDb Top 250 Movies \n\n\nMenuMoviesRelease CalendarTop 250 MoviesMost Popular MoviesBrowse Movies by GenreTop Box OfficeShowtimes & TicketsMovie NewsIndia Movie SpotlightTV ShowsWhat's on TV & StreamingTop 250 TV ShowsMost Popular TV ShowsBrowse TV Shows by GenreTV NewsWatchWhat to WatchLatest TrailersIMDb OriginalsIMDb PicksIMDb SpotlightIMDb PodcastsAwards & EventsOscarsSXSW Film FestivalCannes Film FestivalSTARmeter AwardsAwards CentralFestival CentralAll EventsCelebsBorn TodayMost Popular CelebsCelebrity NewsCommunityHelp CenterContributor ZonePollsFor Industry ProfessionalsLanguageEnglish (United States)LanguageFully supportedEnglish (United States)Partially supportedFrançais (Canada)Français (France)Deutsch (Deutschland)हिंदी (भारत)Italiano (Italia)Português (Brasil)Español (España)Español (México)AllAllTitlesTV EpisodesCelebsCompaniesKeywordsAdvanced SearchWatchlistSign InSign InNew Customer?\xa0Create accountENFully supportedEnglish (United States)Partially supportedFrançais (Canada)Français (France)Deutsch (Deutschland)हिंदी (भारत)Italiano (Italia)Português (Brasil)Español (España)Español (México)Use appIMDb ChartsShareIMDb Top 250 MoviesAs rated by regular IMDb voters.250 TitlesSort byRankingRankingIMDb ratingRelease dateNumber of ratingsAlphabeticalPopularityRuntime1. The Shawshank Redemption19942h 22mR9.3\xa0(2.9M)Rate2. The Godfather19722h 55mR9.2\xa0(2M)Rate3. The Dark Knight20082h 32mPG-139.0\xa0(2.9M)Rate4. The Godfather Part II19743h 22mR9.0\xa0(1.4M)Rate5. 12 Angry Men19571h 36mApproved9.0\xa0(862K)Rate6. Schindler's List19933h 15mR9.0\xa0(1.4M)Rate7. The Lord of the Rings: The Return of the King20033h 21mPG-139.0\xa0(2M)Rate8. Pulp Fiction19942h 34mR8.9\xa0(2.2M)Rate9. The Lord of the Rings: The Fellowship of the Ring20012h 58mPG-138.9\xa0(2M)Rate10. The Good, the Bad and the Ugly19662h 58mApproved8.8\xa0(809K)Rate11. Forrest Gump19942h 22mPG-138.8\xa0(2.3M)Rate12. The Lord of the Rings: The Two Towers20022h 59mPG-138.8\xa0(1.8M)Rate13. Fight Club19992h 19mR8.8\xa0(2.3M)Rate14. Inception20102h 28mPG-138.8\xa0(2.5M)Rate15. Star Wars: Episode V - The Empire Strikes Back19802h 4mPG8.7\xa0(1.4M)Rate16. Dune: Part Two20242h 46mPG-138.8\xa0(320K)Rate17. The Matrix19992h 16mR8.7\xa0(2M)Rate18. Goodfellas19902h 25mR8.7\xa0(1.3M)Rate19. One Flew Over the Cuckoo's Nest19752h 13mR8.7\xa0(1.1M)Rate20. Se7en19952h 7mR8.6\xa0(1.8M)Rate21. Interstellar20142h 49mPG-138.7\xa0(2.1M)Rate22. It's a Wonderful Life19462h 10mPG8.6\xa0(498K)Rate23. Seven Samurai19543h 27mNot Rated8.6\xa0(366K)Rate24. The Silence of the Lambs19911h 58mR8.6\xa0(1.5M)Rate25. Saving Private Ryan19982h 49mR8.6\xa0(1.5M)Rate26. City of God20022h 10mR8.6\xa0(799K)Rate27. Life Is Beautiful19971h 56mPG-138.6\xa0(742K)Rate28. The Green Mile19993h 9mR8.6\xa0(1.4M)Rate29. Terminator 2: Judgment Day19912h 17mR8.6\xa0(1.2M)Rate30. Star Wars: Episode IV - A New Hope19772h 1mPG8.6\xa0(1.4M)Rate31. Back to the Future19851h 56mPG8.5\xa0(1.3M)Rate32. Spirited Away20012h 5mPG8.6\xa0(846K)Rate33. The Pianist20022h 30mR8.5\xa0(909K)Rate34. Parasite20192h 12mR8.5\xa0(954K)Rate35. Psycho19601h 49mR8.5\xa0(717K)Rate36. Spider-Man: Across the Spider-Verse20232h 20mPG8.6\xa0(364K)Rate37. Gladiator20002h 35mR8.5\xa0(1.6M)Rate38. The Lion King19941h 28mG8.5\xa0(1.1M)Rate39. Léon: The Professional19941h 50mR8.5\xa0(1.2M)Rate40. The Departed20062h 31mR8.5\xa0(1.4M)Rate41. American History X19981h 59mR8.5\xa0(1.2M)Rate42. Whiplash20141h 46mR8.5\xa0(985K)Rate43. The Prestige20062h 10mPG-138.5\xa0(1.4M)Rate44. Grave of the Fireflies19881h 29mNot Rated8.5\xa0(309K)Rate45. Harakiri19622h 13mNot Rated8.6\xa0(68K)Rate46. The Usual Suspects19951h 46mR8.5\xa0(1.1M)Rate47. Casablanca19421h 42mPG8.5\xa0(605K)Rate48. The Intouchables20111h 52mR8.5\xa0(927K)Rate49. Cinema Paradiso19882h 54mPG8.5\xa0(282K)Rate50. Modern Times19361h 27mG8.5\xa0(259K)Rate51. Rear Window19541h 52mPG8.5\xa0(521K)Rate52. Once Upon a Time in the West19682h 46mPG-138.5\xa0(349K)Rate53. Alien19791h 57mR8.5\xa0(948K)Rate54. City Lights19311h 27mG8.5\xa0(196K)Rate55. Apocalypse Now19792h 27mR8.4\xa0(709K)Rate56. Django Unchained20122h 45mR8.5\xa0(1.7M)Rate57. Memento20001h 53mR8.4\xa0(1.3M)Rate58. 12th Fail20232h 27m9.0\xa0(109K)Rate59. WALL·E20081h 38mG8.4\xa0(1.2M)Rate60. Raiders of the Lost Ark19811h 55mPG8.4\xa0(1M)Rate61. The Lives of Others20062h 17mR8.4\xa0(409K)Rate62. Sunset Blvd.19501h 50mPassed8.4\xa0(236K)Rate63. Paths of Glory19571h 28mApproved8.4\xa0(212K)Rate64. Avengers: Infinity War20182h 29mPG-138.4\xa0(1.2M)Rate65. Spider-Man: Into the Spider-Verse20181h 57mPG8.4\xa0(668K)Rate66. Witness for the Prosecution19571h 56mApproved8.4\xa0(137K)Rate67. The Shining19802h 26mR8.4\xa0(1.1M)Rate68. The Great Dictator19402h 5mG8.4\xa0(237K)Rate69. Aliens19862h 17mR8.4\xa0(761K)Rate70. Inglourious Basterds20092h 33mR8.4\xa0(1.6M)Rate71. The Dark Knight Rises20122h 44mPG-138.4\xa0(1.8M)Rate72. Dr. Strangelove or: How I Learned to Stop Worrying and Love the Bomb19641h 35mPG8.4\xa0(517K)Rate73. American Beauty19992h 2mR8.3\xa0(1.2M)Rate74. Oldboy20032hR8.3\xa0(634K)Rate75. Coco20171h 45mPG8.4\xa0(588K)Rate76. Amadeus19842h 40mPG8.4\xa0(427K)Rate77. Toy Story19951h 21mG8.3\xa0(1.1M)Rate78. Das Boot19812h 29m8.4\xa0(264K)Rate79. Braveheart19952h 58mR8.3\xa0(1.1M)Rate80. Avengers: Endgame20193h 1mPG-138.4\xa0(1.3M)Rate81. Joker20192h 2mR8.4\xa0(1.5M)Rate82. Princess Mononoke19972h 14mPG-138.3\xa0(433K)Rate83. Good Will Hunting19972h 6mR8.3\xa0(1.1M)Rate84. Your Name.20161h 46m8.4\xa0(318K)Rate85. Once Upon a Time in America19843h 49mR8.3\xa0(377K)Rate86. High and Low19632h 23mNot Rated8.4\xa0(53K)Rate87. 3 Idiots20092h 50mPG-138.4\xa0(433K)Rate88. Singin' in the Rain19521h 43mG8.3\xa0(260K)Rate89. Capernaum20182h 6mR8.4\xa0(105K)Rate90. Requiem for a Dream20001h 42mUnrated8.3\xa0(897K)Rate91. Come and See19852h 22mNot Rated8.4\xa0(97K)Rate92. Oppenheimer20233hR8.3\xa0(711K)Rate93. Toy Story 320101h 43mG8.3\xa0(891K)Rate94. Star Wars: Episode VI - Return of the Jedi19832h 11mPG8.3\xa0(1.1M)Rate95. Eternal Sunshine of the Spotless Mind20041h 48mR8.3\xa0(1.1M)Rate96. The Hunt20121h 55mR8.3\xa0(363K)Rate97. 2001: A Space Odyssey19682h 29mG8.3\xa0(718K)Rate98. Reservoir Dogs19921h 39mR8.3\xa0(1.1M)Rate99. Ikiru19522h 23mNot Rated8.3\xa0(87K)Rate100. Lawrence of Arabia19623h 38mApproved8.3\xa0(314K)Rate101. The Apartment19602h 5mApproved8.3\xa0(196K)Rate102. North by Northwest19592h 16mApproved8.3\xa0(345K)Rate103. Citizen Kane19411h 59mPG8.3\xa0(465K)Rate104. Incendies20102h 11mR8.3\xa0(199K)Rate105. Vertigo19582h 8mPG8.3\xa0(426K)Rate106. M19311h 39mPassed8.3\xa0(168K)Rate107. Double Indemnity19441h 47mPassed8.3\xa0(167K)Rate108. Scarface19832h 50mR8.3\xa0(914K)Rate109. Amélie20012h 2mR8.3\xa0(793K)Rate110. Full Metal Jacket19871h 56mR8.3\xa0(789K)Rate111. Heat19952h 50mR8.3\xa0(718K)Rate112. A Clockwork Orange19712h 16mX8.3\xa0(880K)Rate113. Up20091h 36mPG8.3\xa0(1.1M)Rate114. To Kill a Mockingbird19622h 9mApproved8.3\xa0(332K)Rate115. The Sting19732h 9mPG8.3\xa0(279K)Rate116. A Separation20112h 3mPG-138.3\xa0(258K)Rate117. Indiana Jones and the Last Crusade19892h 7mPG-138.2\xa0(810K)Rate118. Die Hard19882h 12mR8.2\xa0(943K)Rate119. Metropolis19272h 33mNot Rated8.3\xa0(185K)Rate120. Like Stars on Earth20072h 42mPG8.3\xa0(206K)Rate121. Hamilton20202h 40mPG-138.3\xa0(113K)Rate122. Snatch20001h 42mR8.2\xa0(909K)Rate123. L.A. Confidential19972h 18mR8.2\xa0(617K)Rate124. 191720191h 59mR8.2\xa0(673K)Rate125. Bicycle Thieves19481h 29mNot Rated8.3\xa0(175K)Rate126. Taxi Driver19761h 54mR8.2\xa0(918K)Rate127. Downfall20042h 36mR8.2\xa0(375K)Rate128. Dangal20162h 41mNot Rated8.3\xa0(210K)Rate129. For a Few Dollars More19652h 12mR8.2\xa0(274K)Rate130. Batman Begins20052h 20mPG-138.2\xa0(1.6M)Rate131. The Wolf of Wall Street20133hR8.2\xa0(1.6M)Rate132. Some Like It Hot19592h 1mPassed8.2\xa0(283K)Rate133. Green Book20182h 10mPG-138.2\xa0(568K)Rate134. The Kid19211h 8mPassed8.2\xa0(135K)Rate135. The Father20201h 37mPG-138.2\xa0(192K)Rate136. Judgment at Nuremberg19612h 59mApproved8.3\xa0(85K)Rate137. All About Eve19502h 18mPassed8.2\xa0(139K)Rate138. The Truman Show19981h 43mPG8.2\xa0(1.2M)Rate139. Top Gun: Maverick20222h 10mPG-138.2\xa0(692K)Rate140. Shutter Island20102h 18mR8.2\xa0(1.5M)Rate141. There Will Be Blood20072h 38mR8.2\xa0(640K)Rate142. Casino19952h 58mR8.2\xa0(563K)Rate143. Ran19852h 40mR8.2\xa0(136K)Rate144. Jurassic Park19932h 7mPG-138.2\xa0(1.1M)Rate145. The Sixth Sense19991h 47mPG-138.2\xa0(1M)Rate146. Pan's Labyrinth20061h 58mR8.2\xa0(702K)Rate147. Unforgiven19922h 10mR8.2\xa0(435K)Rate148. No Country for Old Men20072h 2mR8.2\xa0(1.1M)Rate149. A Beautiful Mind20012h 15mPG-138.2\xa0(985K)Rate150. The Thing19821h 49mR8.2\xa0(465K)Rate151. The Treasure of the Sierra Madre19482h 6mPassed8.2\xa0(132K)Rate152. Kill Bill: Vol. 120031h 51mR8.2\xa0(1.2M)Rate153. Yojimbo19611h 50mNot Rated8.2\xa0(131K)Rate154. Monty Python and the Holy Grail19751h 31mPG8.2\xa0(569K)Rate155. The Great Escape19632h 52mApproved8.2\xa0(258K)Rate156. Finding Nemo20031h 40mG8.2\xa0(1.1M)Rate157. Rashomon19501h 28mNot Rated8.2\xa0(180K)Rate158. Prisoners20132h 33mR8.2\xa0(807K)Rate159. Howl's Moving Castle20041h 59mPG8.2\xa0(447K)Rate160. The Elephant Man19802h 4mPG8.2\xa0(258K)Rate161. Chinatown19742h 10mR8.1\xa0(349K)Rate162. Dial M for Murder19541h 45mPG8.2\xa0(188K)Rate163. Gone with the Wind19393h 58mPassed8.2\xa0(334K)Rate164. V for Vendetta20052h 12mR8.2\xa0(1.2M)Rate165. Lock, Stock and Two Smoking Barrels19981h 47mR8.1\xa0(615K)Rate166. The Secret in Their Eyes20092h 9mR8.2\xa0(222K)Rate167. Inside Out20151h 35mPG8.1\xa0(783K)Rate168. Raging Bull19802h 9mR8.1\xa0(379K)Rate169. Three Billboards Outside Ebbing, Missouri20171h 55mR8.1\xa0(554K)Rate170. Trainspotting19961h 33mR8.1\xa0(724K)Rate171. The Bridge on the River Kwai19572h 41mPG8.1\xa0(233K)Rate172. Spider-Man: No Way Home20212h 28mPG-138.2\xa0(875K)Rate173. Fargo19961h 38mR8.1\xa0(725K)Rate174. Klaus20191h 36mPG8.2\xa0(189K)Rate175. Catch Me If You Can20022h 21mPG-138.1\xa0(1.1M)Rate176. Warrior20112h 20mPG-138.1\xa0(497K)Rate177. Godzilla Minus One20232h 4mPG-138.3\xa0(48K)Rate178. Gran Torino20081h 56mR8.1\xa0(814K)Rate179. My Neighbor Totoro19881h 26mG8.1\xa0(379K)Rate180. Million Dollar Baby20042h 12mPG-138.1\xa0(721K)Rate181. Harry Potter and the Deathly Hallows: Part 220112h 10mPG-138.1\xa0(946K)Rate182. Children of Heaven19971h 29mPG8.2\xa0(81K)Rate183. 12 Years a Slave20132h 14mR8.1\xa0(740K)Rate184. Blade Runner19821h 57mR8.1\xa0(822K)Rate185. Before Sunrise19951h 41mR8.1\xa0(338K)Rate186. Ben-Hur19593h 32mG8.1\xa0(253K)Rate187. The Grand Budapest Hotel20141h 39mR8.1\xa0(885K)Rate188. Barry Lyndon19753h 5mPG8.1\xa0(183K)Rate189. Gone Girl20142h 29mR8.1\xa0(1.1M)Rate190. Hacksaw Ridge20162h 19mR8.1\xa0(592K)Rate191. The Gold Rush19251h 35mPassed8.1\xa0(118K)Rate192. In the Name of the Father19932h 13mR8.1\xa0(187K)Rate193. Memories of Murder20032h 12mNot Rated8.1\xa0(215K)Rate194. Dead Poets Society19892h 8mPG8.1\xa0(544K)Rate195. On the Waterfront19541h 48mApproved8.1\xa0(164K)Rate196. The General19261h 18mPassed8.1\xa0(98K)Rate197. The Deer Hunter19783h 3mR8.1\xa0(362K)Rate198. Wild Tales20142h 2mR8.1\xa0(216K)Rate199. Mad Max: Fury Road20152hR8.1\xa0(1.1M)Rate200. Monsters, Inc.20011h 32mG8.1\xa0(977K)Rate201. Sherlock Jr.192445mPassed8.2\xa0(57K)Rate202. The Third Man19491h 33mApproved8.1\xa0(182K)Rate203. Wild Strawberries19571h 31mNot Rated8.1\xa0(115K)Rate204. The Wages of Fear19532h 11mNot Rated8.2\xa0(66K)Rate205. Jaws19752h 4mPG8.1\xa0(658K)Rate206. How to Train Your Dragon20101h 38mPG8.1\xa0(798K)Rate207. Mary and Max20091h 32mNot Rated8.1\xa0(187K)Rate208. Mr. Smith Goes to Washington19392h 9mPassed8.1\xa0(121K)Rate209. Ratatouille20071h 51mG8.1\xa0(822K)Rate210. Ford v Ferrari20192h 32mPG-138.1\xa0(470K)Rate211. The Big Lebowski19981h 57mR8.1\xa0(859K)Rate212. Tokyo Story19532h 16mNot Rated8.1\xa0(68K)Rate213. Room20151h 58mR8.1\xa0(449K)Rate214. The Seventh Seal19571h 36mNot Rated8.1\xa0(198K)Rate215. Rocky19762hPG8.1\xa0(627K)Rate216. Logan20172h 17mR8.1\xa0(829K)Rate217. Spotlight20152h 9mR8.1\xa0(501K)Rate218. Hotel Rwanda20042h 1mPG-138.1\xa0(372K)Rate219. Platoon19862hR8.1\xa0(439K)Rate220. The Terminator19841h 47mR8.1\xa0(922K)Rate221. The Passion of Joan of Arc19281h 54mPassed8.1\xa0(61K)Rate222. Before Sunset20041h 20mR8.1\xa0(287K)Rate223. La haine19951h 38mNot Rated8.1\xa0(196K)Rate224. The Best Years of Our Lives19462h 50mApproved8.1\xa0(70K)Rate225. Pirates of the Caribbean: The Curse of the Black Pearl20032h 23mPG-138.1\xa0(1.2M)Rate226. The Exorcist19732h 2mR8.1\xa0(454K)Rate227. Rush20132h 3mR8.1\xa0(512K)Rate228. Jai Bhim20212h 44mApproved8.7\xa0(217K)Rate229. Network19762h 1mR8.1\xa0(170K)Rate230. Stand by Me19861h 29mR8.1\xa0(441K)Rate231. The Wizard of Oz19391h 42mG8.1\xa0(428K)Rate232. The Incredibles20041h 55mPG8.0\xa0(807K)Rate233. Hachi: A Dog's Tale20091h 33mG8.1\xa0(311K)Rate234. The Handmaiden20162h 25mNot Rated8.1\xa0(172K)Rate235. Into the Wild20072h 28mR8.1\xa0(657K)Rate236. My Father and My Son20051h 52mNot Rated8.2\xa0(92K)Rate237. The Sound of Music19652h 52mG8.1\xa0(260K)Rate238. The Battle of Algiers19662h 1mNot Rated8.1\xa0(66K)Rate239. The Grapes of Wrath19402h 9mPassed8.1\xa0(100K)Rate240. To Be or Not to Be19421h 39mPassed8.1\xa0(43K)Rate241. Groundhog Day19931h 41mPG8.0\xa0(684K)Rate242. Amores Perros20002h 34mR8.1\xa0(253K)Rate243. Rebecca19402h 10mApproved8.1\xa0(146K)Rate244. Cool Hand Luke19672h 7mGP8.1\xa0(188K)Rate245. The Iron Giant19991h 26mPG8.1\xa0(227K)Rate246. The Help20112h 26mPG-138.1\xa0(492K)Rate247. It Happened One Night19341h 45mPassed8.1\xa0(112K)Rate248. Dances with Wolves19903h 1mPG-138.0\xa0(290K)Rate249. Aladdin19921h 30mG8.0\xa0(465K)Rate250. Andhadhun20182h 19mNot Rated8.2\xa0(102K)RateThe Top Rated Movie list only includes feature films.Shorts, TV movies, and documentaries are not includedThe list is ranked by a formula which includes the number of ratings each movie received from users, and value of ratings received from regular usersTo be included on the list, a movie must receive ratings from at least 25000 usersLearn more about how list ranking is determined.More to exploreChartsTop Box Office (US)From the past weekendMost Popular MoviesAs determined by IMDb usersTop Rated English MoviesEnglish-language movies as rated by IMDb usersMost Popular TV ShowsAs determined by IMDb usersTop 250 TV ShowsTop 250 as rated by IMDb UsersLowest Rated MoviesBottom 100 as voted by IMDb usersMost Popular CelebsAs determined by IMDb usersMovie NewsRenée Zellweger Set to Return for New ‘Bridget Jones’ Movie4/9/2024by Borys KitThe Hollywood Reporter - Movie NewsNetflix Acquires Horror-Thriller ‘Don’t Move’\xa0Produced by Sam Raimi\xa0(Exclusive)4/9/2024by Matt DonnellyVariety - Film News‘Wish’ Hits 13.2 Million Views on Disney+ in Five Days4/8/2024by Selome HailuVariety - Film NewsBruce Springsteen Movie, With Jeremy Allen White in Talks to Star, Lands at 20th Century Studios4/8/2024by Katcy StephanVariety - Film NewsKevin Costner’s Western Epic ‘Horizon’ Sets Cannes Film Festival Premiere4/8/2024by Ellise ShaferVariety - Film NewsTop Rated Movies by GenreRecently viewedYou have no recently viewed pagesGet the IMDb appSign in for more accessSign in for more accessFollow IMDb on socialGet the IMDb appFor Android and iOSHelpSite IndexIMDbProBox Office MojoLicense IMDb DataPress RoomAdvertisingJobsConditions of UsePrivacy PolicyYour Ads Privacy ChoicesIMDb, an Amazon company© 1990-2024 by IMDb.com, Inc.Back to top\n\n\n\n\n\n", metadata={'source': 'https://m.imdb.com/chart/top/', 'title': 'IMDb Top 250 Movies', 'description': 'As rated by regular IMDb voters.', 'language': 'en-US'})]

Sayfayı aldığımızda bu sayfayla modelimizi besleyebiliriz. Embeddinglerle sayısal temsillere çevireeceğiz. Bu sayısal temsilleri bir vektör veri tabanında tutacağız. Embedding olarak OpenAIEmbeddings modelini kullanacağız.

from langchain_openai import OpenAIEmbeddings 

embeddings = OpenAIEmbeddings()

Bu temsilleri saklayacağımız bir vektör veri tabanı ayarlayacağız. Kullanacağımız veri tabanı FAISS olsun. Bu işlem için FAISS kütüphanesini yüklememiz gerekmektedir.

from langchain_community.vectorstores import FAISS

İndirdiğimiz web sitesindeki verileri bir bütün olarak modele veremeyiz. Belli bir token sayısı vardır. Metni parçalamak için RecursiveCharacterTextSplitter sınıfını import etmek gerekir.

from langchain.text_splitter import RecursiveCharacterTextSplitter

text_splitter = RecursiveCharacterTextSplitter()

documents = text_splitter.split_documents(docs)

RecursiveCharacterTextSplitter sınıfını kullanarak dokümantasyonu parçalamak istersek documents isminde bir değişken alıp daha önce web sayfasında atanan docs değişkenini fonksiyona veririz. Metinler bu sayede parçalanmış olur. Parçalanan metinler için de document değişkenini aşağıdaki gibi yazdırabilirsiniz.

[Document(page_content='IMDb Top 250 Movies', metadata={'source': 'https://m.imdb.com/chart/top/', 'title': 'IMDb Top 250 Movies', 'description': 'As rated by regular IMDb voters.', 'language': 'en-US'}),
Document(page_content="MenuMoviesRelease CalendarTop 250 MoviesMost Popular MoviesBrowse Movies by GenreTop Box OfficeShowtimes & TicketsMovie NewsIndia Movie SpotlightTV ShowsWhat's on TV & StreamingTop 250 TV ShowsMost Popular TV ShowsBrowse TV Shows by GenreTV NewsWatchWhat to WatchLatest TrailersIMDb OriginalsIMDb PicksIMDb SpotlightIMDb PodcastsAwards & EventsOscarsSXSW Film FestivalCannes Film FestivalSTARmeter AwardsAwards CentralFestival CentralAll EventsCelebsBorn TodayMost Popular CelebsCelebrity NewsCommunityHelp CenterContributor ZonePollsFor Industry ProfessionalsLanguageEnglish (United States)LanguageFully supportedEnglish (United States)Partially supportedFrançais (Canada)Français (France)Deutsch (Deutschland)हिंदी (भारत)Italiano (Italia)Português (Brasil)Español (España)Español (México)AllAllTitlesTV EpisodesCelebsCompaniesKeywordsAdvanced SearchWatchlistSign InSign InNew Customer?\xa0Create accountENFully supportedEnglish (United States)Partially supportedFrançais (Canada)Français (France)Deutsch (Deutschland)हिंदी (भारत)Italiano (Italia)Português (Brasil)Español (España)Español (México)Use appIMDb ChartsShareIMDb Top 250 MoviesAs rated by regular IMDb voters.250 TitlesSort byRankingRankingIMDb ratingRelease dateNumber of ratingsAlphabeticalPopularityRuntime1. The Shawshank Redemption19942h 22mR9.3\xa0(2.9M)Rate2. The Godfather19722h 55mR9.2\xa0(2M)Rate3. The Dark Knight20082h 32mPG-139.0\xa0(2.9M)Rate4. The Godfather Part II19743h 22mR9.0\xa0(1.4M)Rate5. 12 Angry Men19571h 36mApproved9.0\xa0(862K)Rate6. Schindler's List19933h 15mR9.0\xa0(1.4M)Rate7. The Lord of the Rings: The Return of the King20033h 21mPG-139.0\xa0(2M)Rate8. Pulp Fiction19942h 34mR8.9\xa0(2.2M)Rate9. The Lord of the Rings: The Fellowship of the Ring20012h 58mPG-138.9\xa0(2M)Rate10. The Good, the Bad and the Ugly19662h 58mApproved8.8\xa0(809K)Rate11. Forrest Gump19942h 22mPG-138.8\xa0(2.3M)Rate12. The Lord of the Rings: The Two Towers20022h 59mPG-138.8\xa0(1.8M)Rate13. Fight Club19992h 19mR8.8\xa0(2.3M)Rate14. Inception20102h 28mPG-138.8\xa0(2.5M)Rate15. Star Wars: Episode V - The Empire Strikes Back19802h 4mPG8.7\xa0(1.4M)Rate16. Dune: Part Two20242h 46mPG-138.8\xa0(320K)Rate17. The Matrix19992h 16mR8.7\xa0(2M)Rate18. Goodfellas19902h 25mR8.7\xa0(1.3M)Rate19. One Flew Over the Cuckoo's Nest19752h 13mR8.7\xa0(1.1M)Rate20. Se7en19952h 7mR8.6\xa0(1.8M)Rate21. Interstellar20142h 49mPG-138.7\xa0(2.1M)Rate22. It's a Wonderful Life19462h 10mPG8.6\xa0(498K)Rate23. Seven Samurai19543h 27mNot Rated8.6\xa0(366K)Rate24. The Silence of the Lambs19911h 58mR8.6\xa0(1.5M)Rate25. Saving Private Ryan19982h 49mR8.6\xa0(1.5M)Rate26. City of God20022h 10mR8.6\xa0(799K)Rate27. Life Is Beautiful19971h 56mPG-138.6\xa0(742K)Rate28. The Green Mile19993h 9mR8.6\xa0(1.4M)Rate29. Terminator 2: Judgment Day19912h 17mR8.6\xa0(1.2M)Rate30. Star Wars: Episode IV - A New Hope19772h 1mPG8.6\xa0(1.4M)Rate31. Back to the Future19851h 56mPG8.5\xa0(1.3M)Rate32. Spirited Away20012h 5mPG8.6\xa0(846K)Rate33. The Pianist20022h 30mR8.5\xa0(909K)Rate34. Parasite20192h 12mR8.5\xa0(954K)Rate35. Psycho19601h 49mR8.5\xa0(717K)Rate36. Spider-Man: Across the Spider-Verse20232h 20mPG8.6\xa0(364K)Rate37. Gladiator20002h 35mR8.5\xa0(1.6M)Rate38. The Lion King19941h 28mG8.5\xa0(1.1M)Rate39. Léon: The Professional19941h 50mR8.5\xa0(1.2M)Rate40. The Departed20062h 31mR8.5\xa0(1.4M)Rate41. American History X19981h 59mR8.5\xa0(1.2M)Rate42. Whiplash20141h 46mR8.5\xa0(985K)Rate43. The Prestige20062h 10mPG-138.5\xa0(1.4M)Rate44. Grave of the Fireflies19881h 29mNot Rated8.5\xa0(309K)Rate45. Harakiri19622h 13mNot Rated8.6\xa0(68K)Rate46. The Usual Suspects19951h 46mR8.5\xa0(1.1M)Rate47. Casablanca19421h 42mPG8.5\xa0(605K)Rate48. The Intouchables20111h 52mR8.5\xa0(927K)Rate49. Cinema Paradiso19882h 54mPG8.5\xa0(282K)Rate50. Modern Times19361h 27mG8.5\xa0(259K)Rate51. Rear Window19541h 52mPG8.5\xa0(521K)Rate52. Once Upon a Time in the West19682h 46mPG-138.5\xa0(349K)Rate53. Alien19791h 57mR8.5\xa0(948K)Rate54. City Lights19311h 27mG8.5\xa0(196K)Rate55. Apocalypse Now19792h 27mR8.4\xa0(709K)Rate56. Django Unchained20122h 45mR8.5\xa0(1.7M)Rate57. Memento20001h 53mR8.4\xa0(1.3M)Rate58. 12th Fail20232h", metadata={'source': 'https://m.imdb.com/chart/top/', 'title': 'IMDb Top 250 Movies', 'description': 'As rated by regular IMDb voters.', 'language': 'en-US'}),
Document(page_content="City Lights19311h 27mG8.5\xa0(196K)Rate55. Apocalypse Now19792h 27mR8.4\xa0(709K)Rate56. Django Unchained20122h 45mR8.5\xa0(1.7M)Rate57. Memento20001h 53mR8.4\xa0(1.3M)Rate58. 12th Fail20232h 27m9.0\xa0(109K)Rate59. WALL·E20081h 38mG8.4\xa0(1.2M)Rate60. Raiders of the Lost Ark19811h 55mPG8.4\xa0(1M)Rate61. The Lives of Others20062h 17mR8.4\xa0(409K)Rate62. Sunset Blvd.19501h 50mPassed8.4\xa0(236K)Rate63. Paths of Glory19571h 28mApproved8.4\xa0(212K)Rate64. Avengers: Infinity War20182h 29mPG-138.4\xa0(1.2M)Rate65. Spider-Man: Into the Spider-Verse20181h 57mPG8.4\xa0(668K)Rate66. Witness for the Prosecution19571h 56mApproved8.4\xa0(137K)Rate67. The Shining19802h 26mR8.4\xa0(1.1M)Rate68. The Great Dictator19402h 5mG8.4\xa0(237K)Rate69. Aliens19862h 17mR8.4\xa0(761K)Rate70. Inglourious Basterds20092h 33mR8.4\xa0(1.6M)Rate71. The Dark Knight Rises20122h 44mPG-138.4\xa0(1.8M)Rate72. Dr. Strangelove or: How I Learned to Stop Worrying and Love the Bomb19641h 35mPG8.4\xa0(517K)Rate73. American Beauty19992h 2mR8.3\xa0(1.2M)Rate74. Oldboy20032hR8.3\xa0(634K)Rate75. Coco20171h 45mPG8.4\xa0(588K)Rate76. Amadeus19842h 40mPG8.4\xa0(427K)Rate77. Toy Story19951h 21mG8.3\xa0(1.1M)Rate78. Das Boot19812h 29m8.4\xa0(264K)Rate79. Braveheart19952h 58mR8.3\xa0(1.1M)Rate80. Avengers: Endgame20193h 1mPG-138.4\xa0(1.3M)Rate81. Joker20192h 2mR8.4\xa0(1.5M)Rate82. Princess Mononoke19972h 14mPG-138.3\xa0(433K)Rate83. Good Will Hunting19972h 6mR8.3\xa0(1.1M)Rate84. Your Name.20161h 46m8.4\xa0(318K)Rate85. Once Upon a Time in America19843h 49mR8.3\xa0(377K)Rate86. High and Low19632h 23mNot Rated8.4\xa0(53K)Rate87. 3 Idiots20092h 50mPG-138.4\xa0(433K)Rate88. Singin' in the Rain19521h 43mG8.3\xa0(260K)Rate89. Capernaum20182h 6mR8.4\xa0(105K)Rate90. Requiem for a Dream20001h 42mUnrated8.3\xa0(897K)Rate91. Come and See19852h 22mNot Rated8.4\xa0(97K)Rate92. Oppenheimer20233hR8.3\xa0(711K)Rate93. Toy Story 320101h 43mG8.3\xa0(891K)Rate94. Star Wars: Episode VI - Return of the Jedi19832h 11mPG8.3\xa0(1.1M)Rate95. Eternal Sunshine of the Spotless Mind20041h 48mR8.3\xa0(1.1M)Rate96. The Hunt20121h 55mR8.3\xa0(363K)Rate97. 2001: A Space Odyssey19682h 29mG8.3\xa0(718K)Rate98. Reservoir Dogs19921h 39mR8.3\xa0(1.1M)Rate99. Ikiru19522h 23mNot Rated8.3\xa0(87K)Rate100. Lawrence of Arabia19623h 38mApproved8.3\xa0(314K)Rate101. The Apartment19602h 5mApproved8.3\xa0(196K)Rate102. North by Northwest19592h 16mApproved8.3\xa0(345K)Rate103. Citizen Kane19411h 59mPG8.3\xa0(465K)Rate104. Incendies20102h 11mR8.3\xa0(199K)Rate105. Vertigo19582h 8mPG8.3\xa0(426K)Rate106. M19311h 39mPassed8.3\xa0(168K)Rate107. Double Indemnity19441h 47mPassed8.3\xa0(167K)Rate108. Scarface19832h 50mR8.3\xa0(914K)Rate109. Amélie20012h 2mR8.3\xa0(793K)Rate110. Full Metal Jacket19871h 56mR8.3\xa0(789K)Rate111. Heat19952h 50mR8.3\xa0(718K)Rate112. A Clockwork Orange19712h 16mX8.3\xa0(880K)Rate113. Up20091h 36mPG8.3\xa0(1.1M)Rate114. To Kill a Mockingbird19622h 9mApproved8.3\xa0(332K)Rate115. The Sting19732h 9mPG8.3\xa0(279K)Rate116. A Separation20112h 3mPG-138.3\xa0(258K)Rate117. Indiana Jones and the Last Crusade19892h 7mPG-138.2\xa0(810K)Rate118. Die Hard19882h 12mR8.2\xa0(943K)Rate119. Metropolis19272h 33mNot Rated8.3\xa0(185K)Rate120. Like Stars on Earth20072h 42mPG8.3\xa0(206K)Rate121. Hamilton20202h 40mPG-138.3\xa0(113K)Rate122. Snatch20001h 42mR8.2\xa0(909K)Rate123. L.A. Confidential19972h 18mR8.2\xa0(617K)Rate124. 191720191h 59mR8.2\xa0(673K)Rate125. Bicycle Thieves19481h 29mNot Rated8.3\xa0(175K)Rate126. Taxi Driver19761h 54mR8.2\xa0(918K)Rate127. Downfall20042h 36mR8.2\xa0(375K)Rate128. Dangal20162h 41mNot Rated8.3\xa0(210K)Rate129. For a Few Dollars More19652h 12mR8.2\xa0(274K)Rate130. Batman Begins20052h 20mPG-138.2\xa0(1.6M)Rate131. The Wolf of Wall Street20133hR8.2\xa0(1.6M)Rate132. Some Like It Hot19592h 1mPassed8.2\xa0(283K)Rate133. Green Book20182h 10mPG-138.2\xa0(568K)Rate134. The Kid19211h 8mPassed8.2\xa0(135K)Rate135. The Father20201h 37mPG-138.2\xa0(192K)Rate136. Judgment at Nuremberg19612h 59mApproved8.3\xa0(85K)Rate137. All About Eve19502h 18mPassed8.2\xa0(139K)Rate138. The Truman Show19981h 43mPG8.2\xa0(1.2M)Rate139. Top Gun: Maverick20222h 10mPG-138.2\xa0(692K)Rate140. Shutter Island20102h 18mR8.2\xa0(1.5M)Rate141. There Will Be", metadata={'source': 'https://m.imdb.com/chart/top/', 'title': 'IMDb Top 250 Movies', 'description': 'As rated by regular IMDb voters.', 'language': 'en-US'}),
Document(page_content="About Eve19502h 18mPassed8.2\xa0(139K)Rate138. The Truman Show19981h 43mPG8.2\xa0(1.2M)Rate139. Top Gun: Maverick20222h 10mPG-138.2\xa0(692K)Rate140. Shutter Island20102h 18mR8.2\xa0(1.5M)Rate141. There Will Be Blood20072h 38mR8.2\xa0(640K)Rate142. Casino19952h 58mR8.2\xa0(563K)Rate143. Ran19852h 40mR8.2\xa0(136K)Rate144. Jurassic Park19932h 7mPG-138.2\xa0(1.1M)Rate145. The Sixth Sense19991h 47mPG-138.2\xa0(1M)Rate146. Pan's Labyrinth20061h 58mR8.2\xa0(702K)Rate147. Unforgiven19922h 10mR8.2\xa0(435K)Rate148. No Country for Old Men20072h 2mR8.2\xa0(1.1M)Rate149. A Beautiful Mind20012h 15mPG-138.2\xa0(985K)Rate150. The Thing19821h 49mR8.2\xa0(465K)Rate151. The Treasure of the Sierra Madre19482h 6mPassed8.2\xa0(132K)Rate152. Kill Bill: Vol. 120031h 51mR8.2\xa0(1.2M)Rate153. Yojimbo19611h 50mNot Rated8.2\xa0(131K)Rate154. Monty Python and the Holy Grail19751h 31mPG8.2\xa0(569K)Rate155. The Great Escape19632h 52mApproved8.2\xa0(258K)Rate156. Finding Nemo20031h 40mG8.2\xa0(1.1M)Rate157. Rashomon19501h 28mNot Rated8.2\xa0(180K)Rate158. Prisoners20132h 33mR8.2\xa0(807K)Rate159. Howl's Moving Castle20041h 59mPG8.2\xa0(447K)Rate160. The Elephant Man19802h 4mPG8.2\xa0(258K)Rate161. Chinatown19742h 10mR8.1\xa0(349K)Rate162. Dial M for Murder19541h 45mPG8.2\xa0(188K)Rate163. Gone with the Wind19393h 58mPassed8.2\xa0(334K)Rate164. V for Vendetta20052h 12mR8.2\xa0(1.2M)Rate165. Lock, Stock and Two Smoking Barrels19981h 47mR8.1\xa0(615K)Rate166. The Secret in Their Eyes20092h 9mR8.2\xa0(222K)Rate167. Inside Out20151h 35mPG8.1\xa0(783K)Rate168. Raging Bull19802h 9mR8.1\xa0(379K)Rate169. Three Billboards Outside Ebbing, Missouri20171h 55mR8.1\xa0(554K)Rate170. Trainspotting19961h 33mR8.1\xa0(724K)Rate171. The Bridge on the River Kwai19572h 41mPG8.1\xa0(233K)Rate172. Spider-Man: No Way Home20212h 28mPG-138.2\xa0(875K)Rate173. Fargo19961h 38mR8.1\xa0(725K)Rate174. Klaus20191h 36mPG8.2\xa0(189K)Rate175. Catch Me If You Can20022h 21mPG-138.1\xa0(1.1M)Rate176. Warrior20112h 20mPG-138.1\xa0(497K)Rate177. Godzilla Minus One20232h 4mPG-138.3\xa0(48K)Rate178. Gran Torino20081h 56mR8.1\xa0(814K)Rate179. My Neighbor Totoro19881h 26mG8.1\xa0(379K)Rate180. Million Dollar Baby20042h 12mPG-138.1\xa0(721K)Rate181. Harry Potter and the Deathly Hallows: Part 220112h 10mPG-138.1\xa0(946K)Rate182. Children of Heaven19971h 29mPG8.2\xa0(81K)Rate183. 12 Years a Slave20132h 14mR8.1\xa0(740K)Rate184. Blade Runner19821h 57mR8.1\xa0(822K)Rate185. Before Sunrise19951h 41mR8.1\xa0(338K)Rate186. Ben-Hur19593h 32mG8.1\xa0(253K)Rate187. The Grand Budapest Hotel20141h 39mR8.1\xa0(885K)Rate188. Barry Lyndon19753h 5mPG8.1\xa0(183K)Rate189. Gone Girl20142h 29mR8.1\xa0(1.1M)Rate190. Hacksaw Ridge20162h 19mR8.1\xa0(592K)Rate191. The Gold Rush19251h 35mPassed8.1\xa0(118K)Rate192. In the Name of the Father19932h 13mR8.1\xa0(187K)Rate193. Memories of Murder20032h 12mNot Rated8.1\xa0(215K)Rate194. Dead Poets Society19892h 8mPG8.1\xa0(544K)Rate195. On the Waterfront19541h 48mApproved8.1\xa0(164K)Rate196. The General19261h 18mPassed8.1\xa0(98K)Rate197. The Deer Hunter19783h 3mR8.1\xa0(362K)Rate198. Wild Tales20142h 2mR8.1\xa0(216K)Rate199. Mad Max: Fury Road20152hR8.1\xa0(1.1M)Rate200. Monsters, Inc.20011h 32mG8.1\xa0(977K)Rate201. Sherlock Jr.192445mPassed8.2\xa0(57K)Rate202. The Third Man19491h 33mApproved8.1\xa0(182K)Rate203. Wild Strawberries19571h 31mNot Rated8.1\xa0(115K)Rate204. The Wages of Fear19532h 11mNot Rated8.2\xa0(66K)Rate205. Jaws19752h 4mPG8.1\xa0(658K)Rate206. How to Train Your Dragon20101h 38mPG8.1\xa0(798K)Rate207. Mary and Max20091h 32mNot Rated8.1\xa0(187K)Rate208. Mr. Smith Goes to Washington19392h 9mPassed8.1\xa0(121K)Rate209. Ratatouille20071h 51mG8.1\xa0(822K)Rate210. Ford v Ferrari20192h 32mPG-138.1\xa0(470K)Rate211. The Big Lebowski19981h 57mR8.1\xa0(859K)Rate212. Tokyo Story19532h 16mNot Rated8.1\xa0(68K)Rate213. Room20151h 58mR8.1\xa0(449K)Rate214. The Seventh Seal19571h 36mNot Rated8.1\xa0(198K)Rate215. Rocky19762hPG8.1\xa0(627K)Rate216. Logan20172h 17mR8.1\xa0(829K)Rate217. Spotlight20152h 9mR8.1\xa0(501K)Rate218. Hotel Rwanda20042h 1mPG-138.1\xa0(372K)Rate219. Platoon19862hR8.1\xa0(439K)Rate220. The Terminator19841h 47mR8.1\xa0(922K)Rate221. The Passion of Joan of Arc19281h 54mPassed8.1\xa0(61K)Rate222.", metadata={'source': 'https://m.imdb.com/chart/top/', 'title': 'IMDb Top 250 Movies', 'description': 'As rated by regular IMDb voters.', 'language': 'en-US'}),
Document(page_content="Hotel Rwanda20042h 1mPG-138.1\xa0(372K)Rate219. Platoon19862hR8.1\xa0(439K)Rate220. The Terminator19841h 47mR8.1\xa0(922K)Rate221. The Passion of Joan of Arc19281h 54mPassed8.1\xa0(61K)Rate222. Before Sunset20041h 20mR8.1\xa0(287K)Rate223. La haine19951h 38mNot Rated8.1\xa0(196K)Rate224. The Best Years of Our Lives19462h 50mApproved8.1\xa0(70K)Rate225. Pirates of the Caribbean: The Curse of the Black Pearl20032h 23mPG-138.1\xa0(1.2M)Rate226. The Exorcist19732h 2mR8.1\xa0(454K)Rate227. Rush20132h 3mR8.1\xa0(512K)Rate228. Jai Bhim20212h 44mApproved8.7\xa0(217K)Rate229. Network19762h 1mR8.1\xa0(170K)Rate230. Stand by Me19861h 29mR8.1\xa0(441K)Rate231. The Wizard of Oz19391h 42mG8.1\xa0(428K)Rate232. The Incredibles20041h 55mPG8.0\xa0(807K)Rate233. Hachi: A Dog's Tale20091h 33mG8.1\xa0(311K)Rate234. The Handmaiden20162h 25mNot Rated8.1\xa0(172K)Rate235. Into the Wild20072h 28mR8.1\xa0(657K)Rate236. My Father and My Son20051h 52mNot Rated8.2\xa0(92K)Rate237. The Sound of Music19652h 52mG8.1\xa0(260K)Rate238. The Battle of Algiers19662h 1mNot Rated8.1\xa0(66K)Rate239. The Grapes of Wrath19402h 9mPassed8.1\xa0(100K)Rate240. To Be or Not to Be19421h 39mPassed8.1\xa0(43K)Rate241. Groundhog Day19931h 41mPG8.0\xa0(684K)Rate242. Amores Perros20002h 34mR8.1\xa0(253K)Rate243. Rebecca19402h 10mApproved8.1\xa0(146K)Rate244. Cool Hand Luke19672h 7mGP8.1\xa0(188K)Rate245. The Iron Giant19991h 26mPG8.1\xa0(227K)Rate246. The Help20112h 26mPG-138.1\xa0(492K)Rate247. It Happened One Night19341h 45mPassed8.1\xa0(112K)Rate248. Dances with Wolves19903h 1mPG-138.0\xa0(290K)Rate249. Aladdin19921h 30mG8.0\xa0(465K)Rate250. Andhadhun20182h 19mNot Rated8.2\xa0(102K)RateThe Top Rated Movie list only includes feature films.Shorts, TV movies, and documentaries are not includedThe list is ranked by a formula which includes the number of ratings each movie received from users, and value of ratings received from regular usersTo be included on the list, a movie must receive ratings from at least 25000 usersLearn more about how list ranking is determined.More to exploreChartsTop Box Office (US)From the past weekendMost Popular MoviesAs determined by IMDb usersTop Rated English MoviesEnglish-language movies as rated by IMDb usersMost Popular TV ShowsAs determined by IMDb usersTop 250 TV ShowsTop 250 as rated by IMDb UsersLowest Rated MoviesBottom 100 as voted by IMDb usersMost Popular CelebsAs determined by IMDb usersMovie NewsRenée Zellweger Set to Return for New ‘Bridget Jones’ Movie4/9/2024by Borys KitThe Hollywood Reporter - Movie NewsNetflix Acquires Horror-Thriller ‘Don’t Move’\xa0Produced by Sam Raimi\xa0(Exclusive)4/9/2024by Matt DonnellyVariety - Film News‘Wish’ Hits 13.2 Million Views on Disney+ in Five Days4/8/2024by Selome HailuVariety - Film NewsBruce Springsteen Movie, With Jeremy Allen White in Talks to Star, Lands at 20th Century Studios4/8/2024by Katcy StephanVariety - Film NewsKevin Costner’s Western Epic ‘Horizon’ Sets Cannes Film Festival Premiere4/8/2024by Ellise ShaferVariety - Film NewsTop Rated Movies by GenreRecently viewedYou have no recently viewed pagesGet the IMDb appSign in for more accessSign in for more accessFollow IMDb on socialGet the IMDb appFor Android and iOSHelpSite IndexIMDbProBox Office MojoLicense IMDb DataPress RoomAdvertisingJobsConditions of UsePrivacy PolicyYour Ads Privacy ChoicesIMDb, an Amazon company© 1990-2024 by IMDb.com, Inc.Back to top", metadata={'source': 'https://m.imdb.com/chart/top/', 'title': 'IMDb Top 250 Movies', 'description': 'As rated by regular IMDb voters.', 'language': 'en-US'})]

İlgili dokümanları embeddinglerle sayısal temsillere çevirme işlemiyle devam edebilirsiniz. Daha sonra bunları veri tabanına indekslemek gerekir. İşte bunun için de FAISS sınıfını kullanmak gerekiyor.

vector = FAISS.from_documents(documents, embeddings)

from_documents metotuna önce dokümantasyonlarımız sonra embedding alanları verilecektir ve böylece HTML sayfası indekslemiş oluruz. Sonrasında bir retrieval chain oluşturacağız. Gelen soruyu alacak, ilgili dokümantasyona bakacak. Bu dokümanları orjinal soruyla birlikte bir modele aktaracak. Model ise bu dokümanlara göre soruyu cevaplayacaktır. Prompt oluşturmak için ChatPromptTemplate sınıfını kullanabilirsiniz.

from langchain_core.prompts import ChatPromptTemplate
prompt = ChatPromptTemplate.from_template(
"""
Answer the following question based only on the provided context:
<context>
{context}
</context>
Question: {input}
"""
)

Prompt oluşturma işlemini “from_template” metoduyla gerçekleştireceğiz. Verilen bağlamı dikkate alarak sadece belirli bir soruya yanıt almak istiyoruz. Bu amaçla, tırnak işaretlerini kullanmamız gerekmektedir. Bağlam kalıbı içine süslü parantez içinde bağlamı yazarak ChatPromptTemplate’i oluşturacağız. Şimdi, dokümanları modele dönüştürmek için bir zincir oluşturalım. Zincir oluşturmak için create_stuff_documents_chain fonksiyonunu kullanacağız.

from langchain_openai import ChatOpenAI 

model = ChatOpenAI()
from langchain.chains.combine_documents import create_stuff_documents_chain
document_chain = create_stuff_documents_chain(model, prompt)

create_stuff_documents_chain fonksiyonuna model ve prompt parametrelerini ekleyelim. Model olarak ChatOpenAI() modelini kullanacağız. Böylece bir doküman zinciri (document_chain) oluşturmuş olacağız. Artık, sorulan soruyla ilgili belgeleri yakalamak için bir Kurtarma zinciri (Retrieval chain) oluşturabiliriz. Bunun için create_retrieval_chain metodu kullanılabilir. Bu metot, vektör tabanlı veritabanındaki belgeleri, önceden oluşturulan document_chain ile birleştirerek, modelin sorulan soruyla ilgili metni yakalamasını sağlar.

from langchain.chains import create_retrieval_chain 

retriever = vector.as_retriever()

retrieval_chain = create_retrieval_chain(retriever, document_chain)

create_retrieval_chain import edildikten sonra vector veri tabanındaki bilgileri yakalama işlemi as_retriever metotuyla retriever değişkenine atanır. Bu bilgilerle document_chain’i birleştirmek için create_retrieval_chain metotu kullanılır. Bu metot çalıştırıldığında retrieval_chain oluşur. Artık sorulan soruyla ilgili bilgileri model IMDB sayfasındaki verileri kullanarak verecektir. Response için retrieval_chain’i kullanalım ve invoke metotunu çağıralım. Süslü parantez içerisinde input bilgisini verelim.

response = retrieval_chain.invoke(
{
"input":"Which movie has the highest IMDB score?"
}
)
response
print(response["answer"])
The movie with the highest IMDB score is "The Shawshank Redemption" with a score of 9.3.

Model IMDB web sitesindeki bilgileri kullanarak en yüksek puanlı filmin The Shawshank Redemption olduğunu getirdi. (Bu arada harika filmdir, izlemeyenler mutlaka izlesin derimm! :) )

Bugünlük benim anlatacaklarım bu kadar ! Alıştırmaların kodlarına https://github.com/KardelRuveyda/langchain-exercises’dan ulaşabilirsiniz.

Sevgiler!

İyi Bayramlar :)🍬❤

--

--

Kardel Rüveyda ÇETİN

Expert Software Engineer @DogusTeknoloji ~ All my life I've been over the top. I don't know what I'm doing. All I know is I don't wanna stop. 🤘