{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "e:\\Coding prac\\HuggingFace\\env_1\\lib\\site-packages\\tqdm\\auto.py:22: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", " from .autonotebook import tqdm as notebook_tqdm\n" ] } ], "source": [ "from datasets import load_dataset\n", "# import torch\n", "import pandas as pd\n", "from transformers import pipeline\n", "from transformers import DistilBertTokenizer, DistilBertModel\n" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Found cached dataset wikitext (C:/Users/Dell/.cache/huggingface/datasets/wikitext/wikitext-2-raw-v1/1.0.0/a241db52902eaf2c6aa732210bead40c090019a499ceb13bcbfa3f8ab646a126)\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ " The game 's battle system , the BliTZ system , is carried over directly from Valkyira Chronicles . During missions , players select each unit using a top @-@ down perspective of the battlefield map : once a character is selected , the player moves the character around the battlefield in third @-@ person . A character can only act once per @-@ turn , but characters can be granted multiple turns at the expense of other characters ' turns . Each character has a field and distance of movement limited by their Action Gauge . Up to nine characters can be assigned to a single mission . During gameplay , characters will call out if something happens to them , such as their health points ( HP ) getting low or being knocked out by enemy attacks . Each character has specific \" Potentials \" , skills unique to each character . They are divided into \" Personal Potential \" , which are innate skills that remain unaltered unless otherwise dictated by the story and can either help or impede a character , and \" Battle Potentials \" , which are grown throughout the game and always grant boons to a character . To learn Battle Potentials , each character has a unique \" Masters Table \" , a grid @-@ based skill table that can be used to acquire and link different skills . Characters also have Special Abilities that grant them temporary boosts on the battlefield : Kurt can activate \" Direct Command \" and move around the battlefield without depleting his Action Point gauge , the character Reila can shift into her \" Valkyria Form \" and become invincible , while Imca can target multiple enemy units with her heavy weapon . \n", "\n" ] } ], "source": [ "data_files = {\"train\": \"wikitext-2-raw-v1\"}\n", "dataset = load_dataset(\"wikitext\",'wikitext-2-raw-v1', split = \"train\")\n", "\n", "train_df = pd.DataFrame(dataset)\n", "sample = train_df.loc[10,'text']\n", "print(sample)" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Some weights of the model checkpoint at distilbert-base-cased were not used when initializing DistilBertModel: ['vocab_transform.bias', 'vocab_layer_norm.bias', 'vocab_projector.weight', 'vocab_projector.bias', 'vocab_transform.weight', 'vocab_layer_norm.weight']\n", "- This IS expected if you are initializing DistilBertModel from the checkpoint of a model trained on another task or with another architecture (e.g. initializing a BertForSequenceClassification model from a BertForPreTraining model).\n", "- This IS NOT expected if you are initializing DistilBertModel from the checkpoint of a model that you expect to be exactly identical (initializing a BertForSequenceClassification model from a BertForSequenceClassification model).\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "{'input_ids': tensor([[ 101, 20777, 17510, 1143, 1118, 1251, 3087, 1128, 112, 173,\n", " 1176, 119, 102]]), 'attention_mask': tensor([[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]])}\n" ] } ], "source": [ "# unmasker = pipeline('fill-mask', model='distilbert-base-uncased')\n", "# unmasker(\"Hello I'm a [MASK] model.\")\n", "\n", "tokenizer = DistilBertTokenizer.from_pretrained('distilbert-base-cased')\n", "model = DistilBertModel.from_pretrained(\"distilbert-base-cased\")\n", "text = \"Replace me by any text you'd like.\"\n", "encoded_input = tokenizer(text, return_tensors='pt')\n", "output = model(**encoded_input)" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[{'score': 0.12178919464349747,\n", " 'token': 2321,\n", " 'token_str': 'battle',\n", " 'sequence': 'The game\\'s battle system, the battle system, is carried over directly from Valkyira Chronicles. During missions, players select each unit using a top @ - @ down perspective of the battlefield map : once a character is selected, the player moves the character around the battlefield in third @ - @ person. A character can only act once per @ - @ turn, but characters can be granted multiple turns at the expense of other characters\\'turns. Each character has a field and distance of movement limited by their Action Gauge. Up to nine characters can be assigned to a single mission. During gameplay, characters will call out if something happens to them, such as their health points ( HP ) getting low or being knocked out by enemy attacks. Each character has specific \" Potentials \", skills unique to each character. They are divided into \" Personal Potential \", which are innate skills that remain unaltered unless otherwise dictated by the story and can either help or impede a character, and \" Battle Potentials \", which are grown throughout the game and always grant boons to a character. To learn Battle Potentials, each character has a unique \" Masters Table \", a grid @ - @ based skill table that can be used to acquire and link different skills. Characters also have Special Abilities that grant them temporary boosts on the battlefield : Kurt can activate \" Direct Command \" and move around the battlefield without depleting his Action Point gauge, the character Reila can shift into her \" Valkyria Form \" and become invincible, while Imca can target multiple enemy units with her heavy weapon.'},\n", " {'score': 0.03860372304916382,\n", " 'token': 4127,\n", " 'token_str': 'combat',\n", " 'sequence': 'The game\\'s battle system, the combat system, is carried over directly from Valkyira Chronicles. During missions, players select each unit using a top @ - @ down perspective of the battlefield map : once a character is selected, the player moves the character around the battlefield in third @ - @ person. A character can only act once per @ - @ turn, but characters can be granted multiple turns at the expense of other characters\\'turns. Each character has a field and distance of movement limited by their Action Gauge. Up to nine characters can be assigned to a single mission. During gameplay, characters will call out if something happens to them, such as their health points ( HP ) getting low or being knocked out by enemy attacks. Each character has specific \" Potentials \", skills unique to each character. They are divided into \" Personal Potential \", which are innate skills that remain unaltered unless otherwise dictated by the story and can either help or impede a character, and \" Battle Potentials \", which are grown throughout the game and always grant boons to a character. To learn Battle Potentials, each character has a unique \" Masters Table \", a grid @ - @ based skill table that can be used to acquire and link different skills. Characters also have Special Abilities that grant them temporary boosts on the battlefield : Kurt can activate \" Direct Command \" and move around the battlefield without depleting his Action Point gauge, the character Reila can shift into her \" Valkyria Form \" and become invincible, while Imca can target multiple enemy units with her heavy weapon.'},\n", " {'score': 0.030435685068368912,\n", " 'token': 13777,\n", " 'token_str': 'battlefield',\n", " 'sequence': 'The game\\'s battle system, the battlefield system, is carried over directly from Valkyira Chronicles. During missions, players select each unit using a top @ - @ down perspective of the battlefield map : once a character is selected, the player moves the character around the battlefield in third @ - @ person. A character can only act once per @ - @ turn, but characters can be granted multiple turns at the expense of other characters\\'turns. Each character has a field and distance of movement limited by their Action Gauge. Up to nine characters can be assigned to a single mission. During gameplay, characters will call out if something happens to them, such as their health points ( HP ) getting low or being knocked out by enemy attacks. Each character has specific \" Potentials \", skills unique to each character. They are divided into \" Personal Potential \", which are innate skills that remain unaltered unless otherwise dictated by the story and can either help or impede a character, and \" Battle Potentials \", which are grown throughout the game and always grant boons to a character. To learn Battle Potentials, each character has a unique \" Masters Table \", a grid @ - @ based skill table that can be used to acquire and link different skills. Characters also have Special Abilities that grant them temporary boosts on the battlefield : Kurt can activate \" Direct Command \" and move around the battlefield without depleting his Action Point gauge, the character Reila can shift into her \" Valkyria Form \" and become invincible, while Imca can target multiple enemy units with her heavy weapon.'},\n", " {'score': 0.012257658876478672,\n", " 'token': 2851,\n", " 'token_str': 'star',\n", " 'sequence': 'The game\\'s battle system, the star system, is carried over directly from Valkyira Chronicles. During missions, players select each unit using a top @ - @ down perspective of the battlefield map : once a character is selected, the player moves the character around the battlefield in third @ - @ person. A character can only act once per @ - @ turn, but characters can be granted multiple turns at the expense of other characters\\'turns. Each character has a field and distance of movement limited by their Action Gauge. Up to nine characters can be assigned to a single mission. During gameplay, characters will call out if something happens to them, such as their health points ( HP ) getting low or being knocked out by enemy attacks. Each character has specific \" Potentials \", skills unique to each character. They are divided into \" Personal Potential \", which are innate skills that remain unaltered unless otherwise dictated by the story and can either help or impede a character, and \" Battle Potentials \", which are grown throughout the game and always grant boons to a character. To learn Battle Potentials, each character has a unique \" Masters Table \", a grid @ - @ based skill table that can be used to acquire and link different skills. Characters also have Special Abilities that grant them temporary boosts on the battlefield : Kurt can activate \" Direct Command \" and move around the battlefield without depleting his Action Point gauge, the character Reila can shift into her \" Valkyria Form \" and become invincible, while Imca can target multiple enemy units with her heavy weapon.'},\n", " {'score': 0.0115329185500741,\n", " 'token': 4160,\n", " 'token_str': 'core',\n", " 'sequence': 'The game\\'s battle system, the core system, is carried over directly from Valkyira Chronicles. During missions, players select each unit using a top @ - @ down perspective of the battlefield map : once a character is selected, the player moves the character around the battlefield in third @ - @ person. A character can only act once per @ - @ turn, but characters can be granted multiple turns at the expense of other characters\\'turns. Each character has a field and distance of movement limited by their Action Gauge. Up to nine characters can be assigned to a single mission. During gameplay, characters will call out if something happens to them, such as their health points ( HP ) getting low or being knocked out by enemy attacks. Each character has specific \" Potentials \", skills unique to each character. They are divided into \" Personal Potential \", which are innate skills that remain unaltered unless otherwise dictated by the story and can either help or impede a character, and \" Battle Potentials \", which are grown throughout the game and always grant boons to a character. To learn Battle Potentials, each character has a unique \" Masters Table \", a grid @ - @ based skill table that can be used to acquire and link different skills. Characters also have Special Abilities that grant them temporary boosts on the battlefield : Kurt can activate \" Direct Command \" and move around the battlefield without depleting his Action Point gauge, the character Reila can shift into her \" Valkyria Form \" and become invincible, while Imca can target multiple enemy units with her heavy weapon.'}]" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "unmasker = pipeline('fill-mask', model='distilbert-base-cased')\n", "unmasker(''' The game 's battle system , the [MASK] system , is carried over directly from Valkyira Chronicles . During missions , players select each unit using a top @-@ down perspective of the battlefield map : once a character is selected , the player moves the character around the battlefield in third @-@ person . A character can only act once per @-@ turn , but characters can be granted multiple turns at the expense of other characters ' turns . Each character has a field and distance of movement limited by their Action Gauge . Up to nine characters can be assigned to a single mission . During gameplay , characters will call out if something happens to them , such as their health points ( HP ) getting low or being knocked out by enemy attacks . Each character has specific \" Potentials \" , skills unique to each character . They are divided into \" Personal Potential \" , which are innate skills that remain unaltered unless otherwise dictated by the story and can either help or impede a character , and \" Battle Potentials \" , which are grown throughout the game and always grant boons to a character . To learn Battle Potentials , each character has a unique \" Masters Table \" , a grid @-@ based skill table that can be used to acquire and link different skills . Characters also have Special Abilities that grant them temporary boosts on the battlefield : Kurt can activate \" Direct Command \" and move around the battlefield without depleting his Action Point gauge , the character Reila can shift into her \" Valkyria Form \" and become invincible , while Imca can target multiple enemy units with her heavy weapon . ''')" ] } ], "metadata": { "kernelspec": { "display_name": "env_1", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.0" }, "orig_nbformat": 4, "vscode": { "interpreter": { "hash": "cb2f8009fa291b9390b5e8b1d79a2dbf902bf48842de693d18e34410753cd5c4" } } }, "nbformat": 4, "nbformat_minor": 2 }