--- license: llama2 datasets: - DehydratedWater42/semantic_relations_extraction language: - en library_name: transformers pipeline_tag: text-generation inference: false --- # SeELLama (Semantic Extraction LLama) Model based on LLama2-7b fine-tuned with `DehydratedWater42/semantic_relations_extraction` dataset. The purpose of this model is to extract semantic relations from text in structured way. ### Try SeELLama in GGUF format [DehydratedWater42/SeELLama-GGUF](https://huggingface.co/DehydratedWater42/SeELLama-GGUF) *** ## How to use it: ### Template: ```text Below is an part of larger text. Your task is to extract information about entities and relations to the JSON format. ### Text Part to Extract From: <> ### Extracted Relations: { "section_description": ``` The `JSON` opening is not necessary but it improves stability. Remember to use double `{{` instead of singular '{' if you are using LangChain prompts with fstring formatting. ### Optimal settings: For Transformer loader -> [text-generation-webui](https://github.com/oobabooga/text-generation-webui): - load-in-4bit=True - user_double_quant=True - trust-remote-code=True - compute_dtype=bfloat16 - quant_type=nf4 For `text-generation-webui` you must add `--trust-remote-code` flag to use the model `./start_linux.sh --trust-remote-code` This is a PerfModel created from 4bit qlora adapter fine-tuned with SFTTrainer with BitsAndBytes merged with quantized LLama2-7b. Model was trained on 2560 context lenght where 1000-1500 tokens where used as input text. Some results may require post processing to close out-of-context jsons. ### Starter code #### Run generation with python ```python from transformers import LlamaForCausalLM, LlamaTokenizerFast, BitsAndBytesConfig model_name = "DehydratedWater42/SeELLama" prompt = """Below is an part of larger text. Your task is to extract information about entities and relations to the JSON format. ### Text Part to Extract From: Players in Survival, Adventure, or Spectator have access to the 2×2 crafting grid from their inventory screen. Small crafting recipes that are at most 2×2 can be made there. These include wooden planks, sticks, crafting tables, torches and some shapeless recipes. To craft items using a bigger grid to allow more crafting recipes, create a crafting table with 4 wooden planks, place it in the world, and press use while facing it. This brings up an interface with a larger, 3×3 crafting grid, which the player can use to craft any crafting recipe in the game. There is also a recipe book where the player can access all the crafting recipes. Some recipes do not require their ingredients to be arranged in a specific way on the crafting grid. These are commonly known as shapeless recipes. For example, players may craft a fermented spider eye by placing its ingredients anywhere within the grid or like a flint and steel can be crafted in any orientation. On the contrary, many recipes must have their ingredients placed in the correct relative positions on the crafting grid. These are commonly known as shaped recipes. Ingredients in shaped recipes can be ‘moved’ up, down, left, or right. They can also be flipped side-ways. For example, a 3×1 recipe, such as bread, can be made using the top, middle, or bottom row of the 3×3 grid, and a bow may be made with the strings placed on the left instead of on the right. There are recipes that may not be moved or mirrored in this way. These are commonly known as fixed recipes. For example, dyes in banner recipes - only available in Bedrock Edition - must be specifically placed to achieve the desired pattern. Fixed recipes can be added by data packs, add-ons, or mods. ### Extracted Relations: { "section_description": """ model = LlamaForCausalLM.from_pretrained(model_name, trust_remote_code=True, device_map="auto") tokenizer = LlamaTokenizerFast.from_pretrained(model_name, trust_remote_code=True, device_map="auto") model.eval() inputs = tokenizer(prompt, return_tensors="pt").to('cuda') outputs = model.generate( inputs['input_ids'], max_length=2500, temperature=0.7, top_p=0.6, top_k=0, repetition_penalty=1, no_repeat_ngram_size=0, do_sample=True, num_return_sequences=1 ) generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True) print(generated_text) ``` #### Extract generated json ```python import json json_start = """{ "section_description": """ to_parse = json_start + generated_text.split(json_start)[1] print(json.loads(to_parse)) ``` ### Example: Extracting information from Minecraft Wiki. #### Initial template ```text Below is an part of larger text. Your task is to extract information about entities and relations to the JSON format. ### Text Part to Extract From: Players in Survival, Adventure, or Spectator have access to the 2×2 crafting grid from their inventory screen. Small crafting recipes that are at most 2×2 can be made there. These include wooden planks, sticks, crafting tables, torches and some shapeless recipes. To craft items using a bigger grid to allow more crafting recipes, create a crafting table with 4 wooden planks, place it in the world, and press use while facing it. This brings up an interface with a larger, 3×3 crafting grid, which the player can use to craft any crafting recipe in the game. There is also a recipe book where the player can access all the crafting recipes. Some recipes do not require their ingredients to be arranged in a specific way on the crafting grid. These are commonly known as shapeless recipes. For example, players may craft a fermented spider eye by placing its ingredients anywhere within the grid or like a flint and steel can be crafted in any orientation. On the contrary, many recipes must have their ingredients placed in the correct relative positions on the crafting grid. These are commonly known as shaped recipes. Ingredients in shaped recipes can be ‘moved’ up, down, left, or right. They can also be flipped side-ways. For example, a 3×1 recipe, such as bread, can be made using the top, middle, or bottom row of the 3×3 grid, and a bow may be made with the strings placed on the left instead of on the right. There are recipes that may not be moved or mirrored in this way. These are commonly known as fixed recipes. For example, dyes in banner recipes - only available in Bedrock Edition - must be specifically placed to achieve the desired pattern. Fixed recipes can be added by data packs, add-ons, or mods. ### Extracted Relations: { "section_description": ``` #### Result (about game): ```text Below is an part of larger text. Your task is to extract information about entities and relations to the JSON format. ### Text Part to Extract From: Players in Survival, Adventure, or Spectator have access to the 2×2 crafting grid from their inventory screen. Small crafting recipes that are at most 2×2 can be made there. These include wooden planks, sticks, crafting tables, torches and some shapeless recipes. To craft items using a bigger grid to allow more crafting recipes, create a crafting table with 4 wooden planks, place it in the world, and press use while facing it. This brings up an interface with a larger, 3×3 crafting grid, which the player can use to craft any crafting recipe in the game. There is also a recipe book where the player can access all the crafting recipes. Some recipes do not require their ingredients to be arranged in a specific way on the crafting grid. These are commonly known as shapeless recipes. For example, players may craft a fermented spider eye by placing its ingredients anywhere within the grid or like a flint and steel can be crafted in any orientation. On the contrary, many recipes must have their ingredients placed in the correct relative positions on the crafting grid. These are commonly known as shaped recipes. Ingredients in shaped recipes can be ‘moved’ up, down, left, or right. They can also be flipped side-ways. For example, a 3×1 recipe, such as bread, can be made using the top, middle, or bottom row of the 3×3 grid, and a bow may be made with the strings placed on the left instead of on the right. There are recipes that may not be moved or mirrored in this way. These are commonly known as fixed recipes. For example, dyes in banner recipes - only available in Bedrock Edition - must be specifically placed to achieve the desired pattern. Fixed recipes can be added by data packs, add-ons, or mods. ### Extracted Relations: { "section_description": "In Minecraft, players can craft items using the 2x2 crafting grid. There are some fixed recipes that require the player to place their ingredients in a specific position.", "list_of_entities": [ "crafting recipes", "player", "fixed recipes", "2x2 crafting grid", "survival, adventure, or spectator players", "wooden planks", "torches", "shaped recipes", "small crafting recipes", "shapeless recipes", "wooden planks, sticks, crafting tables, torches", "flint and steel" ], "relations": [ { "description": "Players have access to the 2x2 crafting grid from their inventory screen.", "source_entities": [ "crafting recipes" ], "target_entities": [ "player" ], "strength": "strong" }, { "description": "Small crafting recipes that are at most 2x2 can be made using the 2x2 crafting grid.", "source_entities": [ "crafting recipes" ], "target_entities": [ "survival, adventure, or spectator players" ], "strength": "strong" }, { "description": "To craft items using a bigger grid to allow more crafting recipes, create a crafting table with 4 wooden planks, place it in the world, and press use while facing it.", "source_entities": [ "crafting recipes" ], "target_entities": [ "wooden planks" ], "strength": "strong" }, { "description": "To craft items using a bigger grid to allow more crafting recipes, create a crafting table with 4 wooden planks, place it in the world, and press use while facing it.", "source_entities": [ "crafting recipes" ], "target_entities": [ "crafting tables" ], "strength": "strong" }, { "description": "Crafting tables allow players to make bigger crafting recipes that are not possible with the 2x2 crafting grid.", "source_entities": [ "crafting recipes" ], "target_entities": [ "torches", "flint and steel", "wooden planks" ], "strength": "strong" }, { "description": "Crafting tables are used to craft items using the 2x2 crafting grid.", "source_entities": [ "crafting recipes" ], "target_entities": [ "wooden planks, sticks, crafting tables, torches" ], "strength": "strong" }, { "description": "There are some fixed recipes that require the player to place their ingredients in a specific position.", "source_entities": [ "crafting recipes" ], "target_entities": [ "fixed recipes" ], "strength": "strong" }, { "description": "The recipes do not require their ingredients to be arranged in a specific way on the crafting grid.", "source_entities": [ "crafting recipes" ], "target_entities": [ "shapeless recipes" ], "strength": "strong" }, { "description": "Ingredients in shapeless recipes can be ‘moved’ up, down, left, or right.", "source_entities": [ "crafting recipes" ], "target_entities": [ "shaped recipes" ], "strength": "strong" }, { "description": "Ingredients in shaped recipes can be flipped side-ways.", "source_entities": [ "crafting recipes" ], "target_entities": [ "fixed recipes" ], "strength": "strong" }, { "description": "There are some fixed recipes that require the player to place their ingredients in a specific position.", "source_entities": [ "crafting recipes" ], "target_entities": [ "fixed recipes" ], "strength": "strong" }, { "description": "The recipes can be added by data packs, add-ons, or mods.", "source_entities": [ "crafting recipes" ], "target_entities": [ "fixed recipes" ], "strength": "strong" } ] } ``` ### Smaller example (About crafting) ```text Below is an part of larger text. Your task is to extract information about entities and relations to the JSON format. ### Text Part to Extract From: Players in Survival, Adventure, or Spectator have access to the 2×2 crafting grid from their inventory screen. Small crafting recipes that are at most 2×2 can be made there. These include wooden planks, sticks, crafting tables, torches and some shapeless recipes. To craft items using a bigger grid to allow more crafting recipes, create a crafting table with 4 wooden planks, place it in the world, and press use while facing it. This brings up an interface with a larger, 3×3 crafting grid, which the player can use to craft any crafting recipe in the game. There is also a recipe book where the player can access all the crafting recipes. ### Extracted Relations: { "section_description": "Survival, Adventure, and Spectator players have access to the 2×2 crafting grid. However, to craft items using a bigger grid, you need to create a crafting table with wooden planks, place it in the world, and press use while facing it.", "list_of_entities": [ "Survival", "wooden planks", "Spectator", "Adventure", "crafting grid" ], "relations": [ { "description": "Survival players can access the 2×2 crafting grid.", "source_entities": [ "Survival" ], "target_entities": [ "crafting grid" ], "strength": "strong" }, { "description": "Adventure and Spectator players can also access the 2×2 crafting grid.", "source_entities": [ "Adventure" ], "target_entities": [ "crafting grid" ], "strength": "strong" }, { "description": "To craft items using a bigger grid, you need to create a crafting table with wooden planks.", "source_entities": [ "Spectator" ], "target_entities": [ "crafting grid" ], "strength": "strong" } ] } ``` ### Longer example (dirt block) ```text Below is an part of larger text. Your task is to extract information about entities and relations to the JSON format. ### Text Part to Extract From: Usage Using bone meal on grass blocks causes short grass, tall grass,‌[Java Edition only] ferns,‌[Bedrock Edition only] and flowers to grow. Passive mobs tend to wander toward grass blocks. They also wander toward light. When a sheep eats a grass block, the block becomes dirt, and a sheared sheep regrows its wool. Baby sheep graze grass much more often than adults and mature 1 minute faster when grazing. Tilling a grass block with a hoe converts it to a farmland block. Dirt paths can be created by using any type of shovel on the side or top of a grass block with air above it. The shovel loses 1 durability for each dirt path block created. Death Grass dies and changes to dirt a random time (when a random tick lands on the block) after it has been covered by any opaque blocks. Transparent blocks can kill grass in a similar manner if they cause the light level above the grass block to be four or below (like water does), and the surrounding area is not otherwise sufficiently illuminated. Spawning In Java Edition, animals occasionally spawn on grass blocks that have light level 9 or brighter in the space directly above. This is quite rare and requires that there be few other animals nearby or in the spawn chunks. Most animals are instead created along with the terrain. In Bedrock Edition, most animals require surface grass blocks (grass blocks with no solid block anywhere above them at the same x, z coordinate) to spawn. Animals regularly spawn in most Overworld biomes on surface grass blocks that have light level 7 or brighter in the space directly above. Snowy grass block A snowy grass block with snow on top of it. Grass blocks turn into a snowy grass block if snow, powder snow or a snow block is placed on top of the block. Removing the snow layer turns the block into a normal grass block. Composting In Bedrock Edition, placing grass blocks into a composter has a 30% chance of raising the compost level by 1. ### Extracted Relations: { "section_description": "The article discusses the various ways in which grass blocks can be used in Minecraft, including as food, fuel, and protection. It also covers how grass blocks can be used to tame animals, and the dangers of being exposed to grass. The article concludes by highlighting the importance of knowing how to use and defend against grass blocks.", "list_of_entities": [ "dirt", "Minecraft", "light level", "animal", "surface grass blocks", "Bedrock Edition", "Java Edition", "dirt path", "grass", "snow", "snowy grass block", "opaque blocks", "sheep", "composter", "transparent blocks" ], "relations": [ { "description": "Grass blocks are a renewable resource that can be used as a food item.", "source_entities": [ "Minecraft", "grass" ], "target_entities": [ "animal", "surface grass blocks" ], "strength": "strong" }, { "description": "Grass blocks can be used to tame animals.", "source_entities": [ "Minecraft", "grass" ], "target_entities": [ "animal", "surface grass blocks" ], "strength": "strong" }, { "description": "Exposure to grass blocks can cause damage to the player's health.", "source_entities": [ "Minecraft" ], "target_entities": [ "grass", "player" ], "strength": "strong" }, { "description": "Placing grass blocks in a composter has a 30% chance of raising the compost level by 1.", "source_entities": [ "Minecraft", "grass" ], "target_entities": [ "composter", "grass" ], "strength": "strong" }, { "description": "Surface grass blocks are the only ones that can be used to spawn animals.", "source_entities": [ "Minecraft" ], "target_entities": [ "surface grass blocks", "animal" ], "strength": "strong" }, { "description": "Animals regularly spawn in most Overworld biomes on surface grass blocks that have light level 7 or brighter in the space directly above.", "source_entities": [ "Minecraft" ], "target_entities": [ "surface grass blocks", "animal" ], "strength": "strong" }, { "description": "If you walk into the grass without first getting rid of any animals or monsters that are there, they will attack you.", "source_entities": [ "Minecraft" ], "target_entities": [ "grass", "player" ], "strength": "moderate" }, { "description": "Placing grass blocks with snow on top of them turns them into snowy grass blocks.", "source_entities": [ "Minecraft" ], "target_entities": [ "snow", "grass" ], "strength": "strong" }, { "description": "Removing the snow layer turns the block into a normal grass block.", "source_entities": [ "Minecraft" ], "target_entities": [ "snowy grass block", "grass" ], "strength": "strong" }, { "description": "Dirt path blocks can be created by using any type of shovel on the side or top of a grass block with air above it.", "source_entities": [ "Minecraft", "grass" ], "target_entities": [ "dirt path", "shovel" ], "strength": "strong" }, { "description": "The shovel loses 1 durability for each dirt path block created.", "source_entities": [ "Minecraft", "shovel" ], "target_entities": [ "dirt path", "shovel" ], "strength": "moderate" }, { "description": "Death grass block dies and changes to dirt a random time (when a random tick lands on the block)", "source_entities": [ "Minecraft" ], "target_entities": [ "death grass block", "dirt" ], "strength": "strong" }, { "description": "Grass can be used to create dirt paths", "source_entities": [ "Minecraft" ], "target_entities": [ "grass", "dirt path" ], "strength": "strong" } ] } ```