Giter Club home page Giter Club logo

mica-actions-agents-and-patients's Introduction

Automatic Identification of Character Actions

We describe a computational model to identify actions and its characters from scene descriptions found in movie scripts. We frame this problem as a semantic-role labeling task, were the model has to label predicates and its constituents as actions, agents, patients or none. This repo contains the code for the transformer-based models, and the data resources used to train these.

Pre-trained Models

SAIL access through Pier

Dataset and pre-trained models can be found in Pier.

External Access

To access the dataset and pre-trained models please fill the form here.

Using the model

The code required to run the model can be found in movieSRL. This code can be used with the pre-trained models or to train your own on new data. To get you running, here are a few steps to follow.

First, import the tag set and create the translation directories. The tagset contains all the SRL tags, and the tag2idx gives us a numerical label for each of these tags

from alltags import *
tag2idx = {t:i for i, t in enumerate(tag_values)}

Model specification

Next, we need to create a BERT configuration. This is where you specify things like the LSTM hidden_size, bidirectionality and the sequence output size (num. of output labels). Here, we extend on the BertConfig object from transformers

from transformers import BertConfig
config = BertConfig.from_pretrained('bert-base-cased')
config.num_labels = len(tag2idx)
config.hidden_size_lstm = FLAGS.hidden_size
config.bidirectional_lstm = FLAGS.bidirectional

With a pre-trained model

After downloading the pre-trained model, unzip it into the MODEL_DIR directory (e.g., something like $HOME/movieSRL-gru50-bilateral). Load the model's weights into a SimpleBERTLSTM instance

from models import SimpleBERTLSTM
model = SimpleBERTLSTM.from_pretrained(MODEL_DIR, config = config)
model.eval()

Input preprocessing

Input processing follows the traditional transformers pipeline. Sentences are tokenized using a pre-trained BertTokenizer (bert-base-cased), transformed into tensors, which the model takes as input.

import torch
import numpy as np
from transformers import BertTokenizer

sent = "Luke, I am your father!"

tokenizer = BertTokenizer.from_pretrained('bert-base-cased')
tokens = torch.tensor([tokenizer.encode(sent)])

with torch.no_grad():
  outputs = model(tokens)

Post-processing

Outputs consist of posterior probabilities over the set of SRL tags. We need to convert it back to a human-readable format.

logits = outputs[0]
predictions = [list(p) for p in np.argmax(logits, axis = 2)]

mica-actions-agents-and-patients's People

Contributors

vrmpx avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.