<jupyter_start><jupyter_text>Inference on diagonalsThe point of this notebook is to see how many terms "on a diagonal" (meaning series which all sum to the same value) the model needs to be trained on before it "learns" all series on the diagonal.<jupyter_code>import pandas as pd
import numpy as np

import random<jupyter_output><empty_output><jupyter_text>Data generation<jupyter_code>def _generate_sample_from_y(n_terms, n_digits, y):
    # Generates a sample which sums to y (used to uniformly distribute the sums)
    x = []
    while len(x) < n_terms - 1:
        # Don't allow it to pick a number causing sum(x) to exceed y, but also subject
        # to the restriction of n_digits.

        # Also, don't allow it to pick such a small number that it would be impossible
        # for the remaining terms to be chosen to sum to y (for example, if y = 150 and
        # n_terms = 2, n_digits = 2, we can't pick 49, or else you would need 101 to sum
        # to y.
        y_upper_bound = y - np.sum(x)
        n_digits_upper_bound = 10 ** n_digits - 1
        upper_bound = min([y_upper_bound, n_digits_upper_bound])
        lower_bound = (y - np.sum(x) - (10 ** n_digits - 1) * (n_terms - len(x) - 1))
        lower_bound = max([0, lower_bound])

        if upper_bound > 0:
            x.append(np.random.randint(lower_bound, upper_bound + 1))
        else:
            x.append(0)
    x.append(y - np.sum(x))
    random.shuffle(x)

    return x, y
_generate_sample_from_y(3, 2, 100)
def all_series_on_diagonal(n_terms, n_digits, y):
    
    X = np.zeros(shape=())<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09158878504672897, 'fraction_numerical': 0.016822429906542057, 'mean_word_length': 2.955665024630542, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '144408', 'license': 'MIT', 'n_tokens_mistral': 577, 'n_tokens_neox': 536, 'n_words': 186, 'path': 'Notebooks/Inference on diagonals.ipynb', 'repo_name': 'paulsavala/Addition-RNN', 'size': '1605'}