def generate_attributes(tokens, attribute_lemmas=attribute_lemmas):
    """
    Given a list of spaCy tokens and a dict of lemma attributes, return an
    AnnoSpan metadata dict with the appropriate attributes object.

    The attribute_lemmas dict should contain keys in the following form:
    {
        "pos_": {
            "attribute_tag": ["lemmas", "to", "match"]
        }
    }

    Multiple attribute tags may be supplied for a given part of speech.
    Possessive nouns are excluded, because they cause problems with
    assumptions elsewhere. This isn't the most elegant solution. A more
    elegant solution might, say, provide a set of conditions (e.g. noun, not
    possessive) and a set of indicator lemmas.
    """
    metadata = {}
    attributes = []
    if not hasattr(tokens, '__iter__'):
        tokens = [tokens]
    for t in tokens:
        if t.pos_ == 'NOUN' and t.dep_ == 'poss':
            continue
        for category, lemmas in attribute_lemmas.get(t.pos_, {}).items():
            if t.lemma_ in lemmas:
                attributes.append(category)
    metadata['attributes'] = attributes
    return metadata
