<jupyter_start><jupyter_text>We are given a sequential corpora i.e a sequence of document collections where the sequence is in a chronological order. This notebook demostrates how to use the orthogonal procrustes method to align the embedding models learned on each document collection separately.<jupyter_code>import gensim
import os
import sys

MOD_DIR = "../modules"

if MOD_DIR not in sys.path: sys.path.append (MOD_DIR)

from utils import seqitertools, w2vutils
from semshift import embeddings, alignment

from utils.w2vutils import EpochLogger
DATA_DIR = "/hg191/corpora/legaldata/sc-docs/"
models = [embeddings.TrainedModel(filename) for filename in seqitertools.iter_files (DATA_DIR, "*.model")]
def sequential_align (trainedmodels):
    aligned_models = list ()
    base_model = None
    first_iter = True
    for model in trainedmodels:
        if first_iter:
            aligned_model = model.m
            first_iter = False
        else:
            aligned_model = alignment.smart_procrustes_align_gensim (base_model, model.m)
        base_model = aligned_model
        aligned_models.append (aligned_model)
    return aligned_models
aligned_models = sequential_align (models)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.06393442622950819, 'fraction_numerical': 0.004098360655737705, 'mean_word_length': 4.108786610878661, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '606504', 'license': 'MIT', 'n_tokens_mistral': 356, 'n_tokens_neox': 347, 'n_words': 112, 'path': 'notebooks/sequential_align.ipynb', 'repo_name': 'sandeepsoni/semantic-progressiveness', 'size': '1220'}