Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to load a text document using a document loader.
Prompt Engineering / GenAI
loader = TextLoader('[1]') documents = loader.load()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a function name instead of a file path.
Forgetting to put the file name in quotes.
✗ Incorrect
The TextLoader requires the file path as a string to load the document correctly.
2fill in blank
mediumComplete the code to load a PDF document using the PDFLoader.
Prompt Engineering / GenAI
loader = PDFLoader('[1]') docs = loader.load()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-PDF file with PDFLoader.
Providing a file with the wrong extension.
✗ Incorrect
PDFLoader expects a PDF file path to load the document properly.
3fill in blank
hardFix the error in the code to load a CSV file using CSVLoader.
Prompt Engineering / GenAI
loader = CSVLoader(file_path='[1]') data = loader.load()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a non-CSV file with CSVLoader.
Incorrect file extension causing loading failure.
✗ Incorrect
CSVLoader requires a CSV file path to load data correctly.
4fill in blank
hardFill both blanks to create a dictionary comprehension that loads documents only if their length is greater than 100.
Prompt Engineering / GenAI
filtered_docs = {doc.id: doc for doc in documents if len(doc.[1]) [2] 100} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'metadata' instead of 'page_content' for length.
Using '<' instead of '>' causing wrong filtering.
✗ Incorrect
We check the length of the document's page_content and filter those greater than 100.
5fill in blank
hardFill all three blanks to create a dictionary comprehension that maps document titles to their content if the content length is less than 500.
Prompt Engineering / GenAI
doc_map = {doc.[1]: doc.[2] for doc in docs if len(doc.[3]) < 500} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using author instead of title for keys.
Mixing up content and metadata in length check.
✗ Incorrect
We use the document's title from metadata as key, page_content as value, and filter by content length less than 500.