File size: 4,406 Bytes
1772cef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2023-10-05T07:20:29.202015200Z",
     "start_time": "2023-10-05T07:20:29.190080700Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "0\n",
      "<torch.cuda.device object at 0x0000028DAB1DB580>\n",
      "1\n",
      "NVIDIA GeForce RTX 3090\n"
     ]
    }
   ],
   "source": [
    "import torch\n",
    "\n",
    "print(torch.cuda.is_available())     # Returns a bool indicating if CUDA is currently available.\n",
    "print(torch.cuda.current_device())   # Returns the index of a currently selected device.\n",
    "print(torch.cuda.device(0))          # Context-manager that changes the selected device.\n",
    "print(torch.cuda.device_count())     # Returns the number of GPUs available.\n",
    "print(torch.cuda.get_device_name(0)) # Gets the name of a device."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2023-10-05 10:37:05,350 SequenceTagger predicts: Dictionary with 20 tags: <unk>, O, S-ORG, S-MISC, B-PER, E-PER, S-PER, S-LOC, B-MISC, E-MISC, B-ORG, E-ORG, I-ORG, I-PER, B-LOC, I-LOC, E-LOC, I-MISC, <START>, <STOP>\n",
      "non_holiday_pred [{'entity_group': 'PER', 'word': 'George Washington', 'start': 0, 'end': 17, 'score': 0.9970293045043945}, {'entity_group': 'LOC', 'word': 'Washington', 'start': 28, 'end': 38, 'score': 0.9996309280395508}]\n"
     ]
    }
   ],
   "source": [
    "from handler import EndpointHandler\n",
    "\n",
    "# init handler\n",
    "my_handler = EndpointHandler(path=\".\")\n",
    "\n",
    "# prepare sample payload\n",
    "non_holiday_payload = {\"inputs\": \"George Washington ging naar Washington\"}\n",
    "\n",
    "\n",
    "# test the handler\n",
    "non_holiday_pred=my_handler(non_holiday_payload)\n",
    "\n",
    "\n",
    "# show results\n",
    "print(\"non_holiday_pred\", non_holiday_pred)\n",
    "\n"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-05T07:37:05.789680900Z",
     "start_time": "2023-10-05T07:37:03.091564500Z"
    }
   },
   "id": "a12c4a4792afc707"
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "outputs": [],
   "source": [
    "from typing import Any, Dict, List\n",
    "import os\n",
    "from flair.data import Sentence\n",
    "from flair.models import SequenceTagger"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-05T07:36:53.389033800Z",
     "start_time": "2023-10-05T07:36:53.382053200Z"
    }
   },
   "id": "f411919d7d047065"
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2023-10-05 10:36:58,072 SequenceTagger predicts: Dictionary with 20 tags: <unk>, O, S-ORG, S-MISC, B-PER, E-PER, S-PER, S-LOC, B-MISC, E-MISC, B-ORG, E-ORG, I-ORG, I-PER, B-LOC, I-LOC, E-LOC, I-MISC, <START>, <STOP>\n"
     ]
    }
   ],
   "source": [
    "tagger = SequenceTagger.load('pytorch_model.bin')"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-05T07:36:59.846440300Z",
     "start_time": "2023-10-05T07:36:54.140093700Z"
    }
   },
   "id": "8f497b3807de2e1"
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "outputs": [
    {
     "data": {
      "text/plain": "'0.12.2'"
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import flair\n",
    "flair.__version__"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "end_time": "2023-10-05T07:36:37.788428800Z",
     "start_time": "2023-10-05T07:36:37.754490Z"
    }
   },
   "id": "df243c485fd370b"
  }
 ],
 "metadata": {
  "kernelspec": {
   "name": "torch",
   "language": "python",
   "display_name": "torch"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}