<jupyter_start><jupyter_text>FrameNetI see three ways of getting features from FrameNet:1. Does word $j$ evoke frame $i$?2. Something with frame relations3. Something with frame elements<jupyter_code>import numpy as np
import pandas as pd
from nltk.corpus import framenet as fn<jupyter_output><empty_output><jupyter_text>1. Does word $j$ evoke frame $i$?**In sum: too sparse to use.**<jupyter_code>def get_lus(frame):
    """Helper to get lexemes from frame."""
    lus = frame['lexUnit'].keys()
    return [k.partition('.')[0] for k in lus]
all_frames = fn.frames('.*')
all_frame_names = [f.name for f in all_frames]
all_lus = [get_lus(f) for f in all_frames]
all_lus = [item for sublist in all_lus for item in sublist]
all_lus = list(set(all_lus))
evoke = pd.DataFrame(0, index=all_frame_names, columns=all_lus)
for frame in all_frames:
    name = frame.name
    lus = get_lus(frame)
    for lu in lus:
        evoke[lu][name] += 1<jupyter_output><empty_output><jupyter_text>Most words evoke one frame, some two, few three.<jupyter_code>evoke.max().value_counts()
evoke.head()<jupyter_output><empty_output><jupyter_text>2. Frame relationsIn this approach, I represent a word by a bit vector indicating whether or not that word evokes a frame or evokes a frame that inherits from a frame.<jupyter_code>def evokes(frame):
    """Return words that evoke `frame`."""
    lus = frame['lexUnit'].keys()
    return [k.partition('.')[0] for k in lus]
def is_inheritance_relation(relation):
    return relation['type']['name'] == 'Inheritance'
def is_parent_frame(frame, relation):
    return frame.name == relation.superFrameName
def children(frame):
    """Return children of `frame`."""
    relations = frame.frameRelations
    relations = [r for r in relations if is_inheritance_relation(r)]
    relations = [r for r in relations if is_parent_frame(frame, r)]
    return [fn.frame(r.subFrameName) for r in relations]
def flatten(lst):
    return [item for sublist in lst for item in sublist]
def words(frame):
    """Return all words that evoke `frame`, including words that
    evoke frames that inherit from `frame`."""
    kids = children(frame)
    if not kids:
        return evokes(frame)
    evoke_sub_frames = [words(f) for f in kids]
    return evokes(frame) + flatten(evoke_sub_frames)
relations = pd.DataFrame(0, index=all_frame_names, columns=all_lus)
for frame in all_frames:
    name = frame.name
    lus = words(frame)
    for lu in lus:
        relations.loc[name, lu] += 1
relations.head()
(relations.size - np.count_nonzero(relations.values))/relations.size
relations.sum(axis=1).sort_values(ascending=False).head()
relations.loc['Transitive_action'].sort_values(ascending=False).head()
relations.to_csv('framenet-relations.csv')
normalized_relations = relations / relations.sum()
normalized_relations.to_csv('framenet-normalized-relations.csv')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11833910034602076, 'fraction_numerical': 0.004152249134948097, 'mean_word_length': 4.948559670781893, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '223874', 'license': 'MIT', 'n_tokens_mistral': 978, 'n_tokens_neox': 956, 'n_words': 275, 'path': 'semrep/data/evaluation/framenet/framenet.ipynb', 'repo_name': 'geoffbacon/semrep', 'size': '2890'}