def slice_trigram(example):
    """Does the target word share a trigram between sentences?"""

    def get_ngrams(tokens, window=1):
        num_ngrams = len(tokens) - window + 1
        for i in range(num_ngrams):
            yield tokens[i : i + window]

    trigrams = []
    for sent, sent_idx in [
        (example.sentence1, example.sentence1_idx),
        (example.sentence2, example.sentence2_idx),
    ]:
        tokens = sent.split()
        trigrams.append(
            [
                " ".join(ngram).lower()
                for ngram in get_ngrams(tokens[sent_idx - 2 : sent_idx + 2], window=3)
                if len(ngram) == 3
            ]
        )
    return len(set(trigrams[0]).intersection(set(trigrams[1]))) > 0