ElcaidaProjects commited on
Commit
90a4a9c
·
verified ·
1 Parent(s): 0d7b67b

Upload 110M-3Grams.pt

Browse files

import numpy as np
import pandas as pd
from tqdm import tqdm
tqdm.pandas()

# Your Constants
X_MIN, X_MAX, Y_MIN = -6.1581, 6.1207, -2.9879
BASE_OFFSET = 0
X_MAX_TOKEN = int(round((X_MAX - X_MIN) * 10000)) + BASE_OFFSET

def tokenize_x_path_fast(float_list):
# 1. Convert to a NumPy array (using float32 to save initial memory)
arr = np.array(float_list, dtype=np.float32)
# 2. Vectorize the math, round, and aggressively cast to 32-bit integers
tokens = np.round((arr - X_MIN) * 10000) + BASE_OFFSET
return tokens.astype(np.int32)

def tokenize_y_path_fast(float_list):
arr = np.array(float_list, dtype=np.float32)
tokens = np.round((arr - Y_MIN) * 10000) + (X_MAX_TOKEN + 1)
return tokens.astype(np.int32)

# Overwrite the columns directly.
# Storing NumPy arrays in the DataFrame column takes drastically less memory than lists.
df['sequence_token'] = df['sequence'].progress_apply(tokenize_x_path_fast)


df['sequence'] = [
[val for pair in zip(x, y) for val in pair]
for x, y in zip(df['x_path'], df['y_path'])
]


from tqdm import tqdm
tqdm.pandas()
def create_3grams(lst):
# Check if it's a list and has at least 3 elements
if not isinstance(lst, list) or len(lst) < 3:
return []

# Create the consecutive 3-grams
return [lst[i:i+3] for i in range(len(lst) - 2)]

# 3. Apply the function using progress_apply
df['y_path'] = df['y_path'].progress_apply(create_3grams)
df['x_path'] = df['x_path'].progress_apply(create_3grams)


df

Files changed (1) hide show
  1. 110M-3Grams.pt +3 -0
110M-3Grams.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4a3a94925e688db5ae2466cbb414dcfd9dd3f8d00974cc25bd5d1a00a901e4fd
3
+ size 2697610693