{ "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", "\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: , 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, , \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: , 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, , \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 }