File size: 2,188 Bytes
2df4ccc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "provenance": []
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "cells": [
    {
      "cell_type": "code",
      "execution_count": 1,
      "metadata": {
        "id": "HTQFPahcInfL"
      },
      "outputs": [],
      "source": [
        "%%capture\n",
        "!pip install transformers\n",
        "!pip install einops\n",
        "\n",
        "import torch\n",
        "from transformers import AutoModelForCausalLM, AutoTokenizer\n",
        "\n",
        "model = AutoModelForCausalLM.from_pretrained(\"agonh/phi-1_5\", trust_remote_code=True)\n",
        "tokenizer = AutoTokenizer.from_pretrained(\"agonh/phi-1_5\", trust_remote_code=True)"
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "prompt = \"tell me about moon ?\"\n",
        "inputs = tokenizer(prompt, return_tensors=\"pt\", return_attention_mask=False)\n",
        "\n",
        "outputs = model.generate(**inputs, max_length=100)\n",
        "text = tokenizer.batch_decode(outputs)[0]\n",
        "print(text)"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "ty9IBkPPZodx",
        "outputId": "40de5c2d-f9d4-4c41-a103-6a07c66c0d14"
      },
      "execution_count": 2,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "tell me about moon?\n",
            "\n",
            "A:\n",
            "\n",
            "The moon is a natural satellite of the Earth. It is the fifth largest moon in the solar system. It is also the only natural satellite of the Earth.\n",
            "\n",
            "A:\n",
            "\n",
            "The moon is a natural satellite of the Earth. It is the fifth largest moon in the solar system. It is also the only natural satellite of the Earth.\n",
            "\n",
            "A:\n",
            "\n",
            "The moon is a natural satellite of the Earth. It is the\n"
          ]
        }
      ]
    }
  ]
}