|
| 1 | +## Generative Representational Instruction Tuning (GRIT) Example |
| 2 | +[gritlm] a model which can generate embeddings as well as "normal" text |
| 3 | +generation depending on the instructions in the prompt. |
| 4 | + |
| 5 | +* Paper: https://arxiv.org/pdf/2402.09906.pdf |
| 6 | + |
| 7 | +### Retrieval-Augmented Generation (RAG) use case |
| 8 | +One use case for `gritlm` is to use it with RAG. If we recall how RAG works is |
| 9 | +that we take documents that we want to use as context, to ground the large |
| 10 | +language model (LLM), and we create token embeddings for them. We then store |
| 11 | +these token embeddings in a vector database. |
| 12 | + |
| 13 | +When we perform a query, prompt the LLM, we will first create token embeddings |
| 14 | +for the query and then search the vector database to retrieve the most |
| 15 | +similar vectors, and return those documents so they can be passed to the LLM as |
| 16 | +context. Then the query and the context will be passed to the LLM which will |
| 17 | +have to _again_ create token embeddings for the query. But because gritlm is used |
| 18 | +the first query can be cached and the second query tokenization generation does |
| 19 | +not have to be performed at all. |
| 20 | + |
| 21 | +### Running the example |
| 22 | +Download a Grit model: |
| 23 | +```console |
| 24 | +$ scripts/hf.sh --repo cohesionet/GritLM-7B_gguf --file gritlm-7b_q4_1.gguf |
| 25 | +``` |
| 26 | + |
| 27 | +Run the example using the downloaded model: |
| 28 | +```console |
| 29 | +$ ./gritlm -m gritlm-7b_q4_1.gguf |
| 30 | + |
| 31 | +Cosine similarity between "Bitcoin: A Peer-to-Peer Electronic Cash System" and "A purely peer-to-peer version of electronic cash w" is: 0.605 |
| 32 | +Cosine similarity between "Bitcoin: A Peer-to-Peer Electronic Cash System" and "All text-based language problems can be reduced to" is: 0.103 |
| 33 | +Cosine similarity between "Generative Representational Instruction Tuning" and "A purely peer-to-peer version of electronic cash w" is: 0.112 |
| 34 | +Cosine similarity between "Generative Representational Instruction Tuning" and "All text-based language problems can be reduced to" is: 0.547 |
| 35 | + |
| 36 | +Oh, brave adventurer, who dared to climb |
| 37 | +The lofty peak of Mt. Fuji in the night, |
| 38 | +When shadows lurk and ghosts do roam, |
| 39 | +And darkness reigns, a fearsome sight. |
| 40 | + |
| 41 | +Thou didst set out, with heart aglow, |
| 42 | +To conquer this mountain, so high, |
| 43 | +And reach the summit, where the stars do glow, |
| 44 | +And the moon shines bright, up in the sky. |
| 45 | + |
| 46 | +Through the mist and fog, thou didst press on, |
| 47 | +With steadfast courage, and a steadfast will, |
| 48 | +Through the darkness, thou didst not be gone, |
| 49 | +But didst climb on, with a steadfast skill. |
| 50 | + |
| 51 | +At last, thou didst reach the summit's crest, |
| 52 | +And gazed upon the world below, |
| 53 | +And saw the beauty of the night's best, |
| 54 | +And felt the peace, that only nature knows. |
| 55 | + |
| 56 | +Oh, brave adventurer, who dared to climb |
| 57 | +The lofty peak of Mt. Fuji in the night, |
| 58 | +Thou art a hero, in the eyes of all, |
| 59 | +For thou didst conquer this mountain, so bright. |
| 60 | +``` |
| 61 | + |
| 62 | +[gritlm]: https://github.com/ContextualAI/gritlm |
0 commit comments