Skip to content

Instantly share code, notes, and snippets.

View naturale0's full-sized avatar

Sihyung Park naturale0

View GitHub Profile
@naturale0
naturale0 / splines.py
Last active October 9, 2024 04:29 — forked from ahwillia/msplines.py
Generate M-spline and I-spline functions in Python
"""
Python code to generate M-splines and I-splines.
References
----------
Ramsay, J. O. (1988). Monotone regression splines in action.
Statistical science, 3(4), 425-441.
"""
import numpy as np
import itertools
from torchtext.experimental.datasets import TextClassificationDataset
from torchtext.vocab import build_vocab_from_iterator
from torchtext.experimental.functional import sequential_transforms
from torchtext.experimental.datasets import IMDB
from torchtext.data.utils import get_tokenizer
from torch.nn.utils.rnn import pack_padded_sequence
def build_char_vocab(data, index, bow="<w>", eow="</w>"):