|
100 | 100 | "from unstructured.partition.html import partition_html\n",
|
101 | 101 | "from unstructured.chunking.title import chunk_by_title\n",
|
102 | 102 | "\n",
|
103 |
| - "import os\n", |
104 |
| - "co = cohere.Client(os.environ[\"COHERE_API_KEY\"])" |
| 103 | + "co = cohere.Client(\"COHERE_API_KEY\")" |
105 | 104 | ]
|
106 | 105 | },
|
107 | 106 | {
|
|
330 | 329 | },
|
331 | 330 | {
|
332 | 331 | "cell_type": "code",
|
333 |
| - "execution_count": 28, |
| 332 | + "execution_count": 53, |
334 | 333 | "metadata": {},
|
335 | 334 | "outputs": [
|
336 | 335 | {
|
|
410 | 409 | " response = co.chat(message=message, search_queries_only=True)\n",
|
411 | 410 | "\n",
|
412 | 411 | " # If there are search queries, retrieve documents and respond\n",
|
| 412 | + " preamble_override = \"You only answer questions using on the documents you have provided with\"\n", |
| 413 | + " \n", |
413 | 414 | " if response.search_queries:\n",
|
414 | 415 | " print(\"Retrieving information...\")\n",
|
415 | 416 | "\n",
|
416 | 417 | " documents = self.retrieve_docs(response)\n",
|
417 | 418 | "\n",
|
418 | 419 | " response = co.chat(\n",
|
419 | 420 | " message=message,\n",
|
| 421 | + " preamble_override = preamble_override,\n", |
420 | 422 | " documents=documents,\n",
|
421 | 423 | " conversation_id=self.conversation_id,\n",
|
422 | 424 | " stream=True,\n",
|
|
428 | 430 | " # If there is no search query, directly respond\n",
|
429 | 431 | " else:\n",
|
430 | 432 | " response = co.chat(\n",
|
431 |
| - " message=message, \n", |
| 433 | + " message=message,\n", |
| 434 | + " preamble_override = preamble_override,\n", |
432 | 435 | " conversation_id=self.conversation_id, \n",
|
433 | 436 | " stream=True\n",
|
434 | 437 | " )\n",
|
|
475 | 478 | },
|
476 | 479 | {
|
477 | 480 | "cell_type": "code",
|
478 |
| - "execution_count": 37, |
| 481 | + "execution_count": 50, |
479 | 482 | "metadata": {},
|
480 | 483 | "outputs": [
|
481 | 484 | {
|
|
719 | 722 | },
|
720 | 723 | {
|
721 | 724 | "cell_type": "code",
|
722 |
| - "execution_count": 38, |
| 725 | + "execution_count": 56, |
723 | 726 | "metadata": {},
|
724 | 727 | "outputs": [
|
725 | 728 | {
|
|
762 | 765 | "name": "stdout",
|
763 | 766 | "output_type": "stream",
|
764 | 767 | "text": [
|
765 |
| - "User: embedding\n", |
| 768 | + "User: hello\n", |
| 769 | + "Chatbot:\n", |
| 770 | + "Hello to you as well! How can I help you today?\n", |
| 771 | + "\n", |
| 772 | + "Let me know if there's something specific you would like to discuss or any questions you have and I'll do my best to assist you.\n", |
| 773 | + "----------------------------------------------------------------------------------------------------\n", |
| 774 | + "\n", |
| 775 | + "User: what is the difference between word and sentence embeddings\n", |
766 | 776 | "Chatbot:\n",
|
767 | 777 | "Retrieving information...\n",
|
768 |
| - "Embedding is a way to locate each sentence in space, in a way that similar sentences are located close by. It associates each sentence with a particular list of numbers (a vector). Word and sentence embeddings are the bread and butter of language models. In Chapter 9 of the Cohere documentation, there is an example of trying to fit a French sentence (\"Bonjour, comment ça va?\") into an embedding and the struggle it will have to understand that it should be close to the English sentence (\"Hello, how are you?\"). Cohere has trained a large multilingual model to unify many languages into one and be able to understand text in all those languages.\n", |
| 778 | + "Word embeddings and sentence embeddings are the fundamental components of LLMs and transform language into computer-readable numbers. \n", |
| 779 | + "\n", |
| 780 | + "Word embeddings associate words with lists of numbers (vectors) in a way that similar words are grouped close together. Sentence embeddings do the same thing but for sentences. It associates vectors to every sentence.\n", |
769 | 781 | "\n",
|
770 | 782 | "CITATIONS:\n",
|
771 |
| - "{'start': 22, 'end': 51, 'text': 'locate each sentence in space', 'document_ids': ['doc_1']}\n", |
772 |
| - "{'start': 67, 'end': 106, 'text': 'similar sentences are located close by.', 'document_ids': ['doc_1']}\n", |
773 |
| - "{'start': 110, 'end': 168, 'text': 'associates each sentence with a particular list of numbers', 'document_ids': ['doc_1']}\n", |
774 |
| - "{'start': 169, 'end': 179, 'text': '(a vector)', 'document_ids': ['doc_1']}\n", |
775 |
| - "{'start': 181, 'end': 254, 'text': 'Word and sentence embeddings are the bread and butter of language models.', 'document_ids': ['doc_2']}\n", |
776 |
| - "{'start': 258, 'end': 295, 'text': 'Chapter 9 of the Cohere documentation', 'document_ids': ['doc_0']}\n", |
777 |
| - "{'start': 320, 'end': 351, 'text': 'trying to fit a French sentence', 'document_ids': ['doc_0']}\n", |
778 |
| - "{'start': 402, 'end': 489, 'text': 'the struggle it will have to understand that it should be close to the English sentence', 'document_ids': ['doc_0']}\n", |
779 |
| - "{'start': 515, 'end': 593, 'text': 'Cohere has trained a large multilingual model to unify many languages into one', 'document_ids': ['doc_0']}\n", |
780 |
| - "{'start': 598, 'end': 648, 'text': 'be able to understand text in all those languages.', 'document_ids': ['doc_0']}\n", |
| 783 | + "{'start': 0, 'end': 15, 'text': 'Word embeddings', 'document_ids': ['doc_0', 'doc_1', 'doc_2']}\n", |
| 784 | + "{'start': 20, 'end': 39, 'text': 'sentence embeddings', 'document_ids': ['doc_0', 'doc_1', 'doc_2']}\n", |
| 785 | + "{'start': 48, 'end': 78, 'text': 'fundamental components of LLMs', 'document_ids': ['doc_2']}\n", |
| 786 | + "{'start': 83, 'end': 133, 'text': 'transform language into computer-readable numbers.', 'document_ids': ['doc_2']}\n", |
| 787 | + "{'start': 136, 'end': 255, 'text': 'Word embeddings associate words with lists of numbers (vectors) in a way that similar words are grouped close together.', 'document_ids': ['doc_0']}\n", |
| 788 | + "{'start': 256, 'end': 312, 'text': 'Sentence embeddings do the same thing but for sentences.', 'document_ids': ['doc_0', 'doc_1']}\n", |
| 789 | + "{'start': 316, 'end': 353, 'text': 'associates vectors to every sentence.', 'document_ids': ['doc_0', 'doc_1']}\n", |
781 | 790 | "\n",
|
782 | 791 | "\n",
|
783 | 792 | "DOCUMENTS:\n",
|
784 |
| - "{'id': 'doc_1', 'text': 'In the previous chapter, we learned that sentence embeddings are the bread and butter of language models, as they associate each sentence with a particular list of numbers (a vector), in a way that similar sentences give similar vectors. We can think of embeddings as a way to locate each sentence in space (a high dimensional space, but a space nonetheless), in a way that similar sentences are located close by. Once we have each sentence somewhere in space, it’s natural to think of distances betw', 'title': 'Similarity Between Words and Sentences', 'url': 'https://docs.cohere.com/docs/similarity-between-words-and-sentences'}\n", |
785 |
| - "{'id': 'doc_2', 'text': 'Text Embeddings\\n\\nWord and sentence embeddings are the bread and butter of language models. This chapter shows a very simple introduction to what they are.', 'title': 'Text Embeddings', 'url': 'https://docs.cohere.com/docs/text-embeddings'}\n", |
786 |
| - "{'id': 'doc_0', 'text': 'Most word and sentence embeddings are dependent on the language that the model is trained on. If you were to try to fit the French sentence “Bonjour, comment ça va?” (meaning: hello, how are you?) in the embedding from the previous section, it will struggle to understand that it should be close to the sentence “Hello, how are you?” in English. For the purpose of unifying many languages into one, and being able to understand text in all these languages, Cohere has trained a large multilingual mod', 'title': 'Text Embeddings', 'url': 'https://docs.cohere.com/docs/text-embeddings'}\n", |
| 793 | + "{'id': 'doc_0', 'text': 'In the previous chapters, you learned about word and sentence embeddings and similarity between words and sentences. In short, a word embedding is a way to associate words with lists of numbers (vectors) in such a way that similar words are associated with numbers that are close by, and dissimilar words with numbers that are far away from each other. A sentence embedding does the same thing, but associating a vector to every sentence. Similarity is a way to measure how similar two words (or sent', 'title': 'The Attention Mechanism', 'url': 'https://docs.cohere.com/docs/the-attention-mechanism'}\n", |
| 794 | + "{'id': 'doc_1', 'text': 'This is where sentence embeddings come into play. A sentence embedding is just like a word embedding, except it associates every sentence with a vector full of numbers, in a coherent way. By coherent, I mean that it satisfies similar properties as a word embedding. For instance, similar sentences are assigned to similar vectors, different sentences are assigned to different vectors, and most importantly, each of the coordinates of the vector identifies some (whether clear or obscure) property of', 'title': 'Text Embeddings', 'url': 'https://docs.cohere.com/docs/text-embeddings'}\n", |
| 795 | + "{'id': 'doc_2', 'text': 'Conclusion\\n\\nWord and sentence embeddings are the bread and butter of LLMs. They are the basic building block of most language models, since they translate human speak (words) into computer speak (numbers) in a way that captures many relations between words, semantics, and nuances of the language, into equations regarding the corresponding numbers.', 'title': 'Text Embeddings', 'url': 'https://docs.cohere.com/docs/text-embeddings'}\n", |
| 796 | + "\n", |
| 797 | + "----------------------------------------------------------------------------------------------------\n", |
| 798 | + "\n", |
| 799 | + "User: continue\n", |
| 800 | + "Chatbot:\n", |
| 801 | + "In some models, the same underlying architecture is used for both word and sentence embeddings. Word embeddings generate vector representations for individual words, while sentence embeddings generate vector representations for entire sentences or phrases.\n", |
| 802 | + "\n", |
| 803 | + "Here's a simple analogy: \n", |
| 804 | + "\n", |
| 805 | + "Word embeddings are like individuals creating unique fingerprints, identifying unique characteristics. Sentence embeddings are like creating a unique fingerprint for each sentence or phrase. \n", |
| 806 | + "\n", |
| 807 | + "Although the concept is similar, the processes are different as word embeddings focus on individual words, while sentence embeddings focus on the entire sentence and capture the overall meaning or context.\n", |
| 808 | + "----------------------------------------------------------------------------------------------------\n", |
| 809 | + "\n", |
| 810 | + "User: what do you know about graph neural networks\n", |
| 811 | + "Chatbot:\n", |
| 812 | + "Retrieving information...\n", |
| 813 | + "I cannot find any specific information on Graph Neural Networks, however, I can provide some information on Transformer Models which are another type of neural network. \n", |
| 814 | + "\n", |
| 815 | + " Transformer models are a type of neural network that utilizes attention mechanisms to parse input sequences into multiple layers, with each layer assigning attention weights to the previous layer. Introduced in the paper \"Attention is All You Need\", they have become one of the key components in many NLP applications and are highly effective due to their ability to handle long-range dependencies and capture contextual information.\n", |
787 | 816 | "\n",
|
| 817 | + "Would you like me to provide more information on Transformer Models or explain other types of neural networks?\n", |
788 | 818 | "----------------------------------------------------------------------------------------------------\n",
|
789 | 819 | "\n",
|
790 | 820 | "Ending chat.\n"
|
|
799 | 829 | "app = App(chatbot)\n",
|
800 | 830 | "\n",
|
801 | 831 | "# Run the chatbot\n",
|
802 |
| - "app.run()\n" |
| 832 | + "app.run()" |
803 | 833 | ]
|
804 | 834 | },
|
805 | 835 | {
|
|
0 commit comments