### Environment Setup and Configuration with Keras Source: https://context7.com/awsaf49/ai-math-olympiad/llms.txt Configures the Keras backend to JAX and sets memory fraction for optimal performance. It also defines a configuration class for hyperparameters and sets the random seed for reproducibility. ```python import os os.environ["KERAS_BACKEND"] = "jax" # Options: "jax", "tensorflow", "torch" os.environ["XLA_PYTHON_CLIENT_MEM_FRACTION"] = "0.9" # Avoid memory fragmentation import keras import keras_nlp import numpy as np import pandas as pd # Configuration class for hyperparameters class CFG: seed = 42 dataset_path = "/kaggle/input/ai-mathematical-olympiad-prize" preset = "gemma_1.1_instruct_2b_en" # Pretrained Gemma model sequence_length = 512 # Max input sequence length batch_size = 1 epochs = 1 # Set random seed for reproducibility keras.utils.set_random_seed(CFG.seed) ``` -------------------------------- ### Install KerasNLP Library Source: https://github.com/awsaf49/ai-math-olympiad/blob/main/notebooks/aimo-kerasnlp-starter.ipynb Installs the KerasNLP library from a local wheel file. This is necessary when internet access is restricted during inference. The installation is quiet and does not require additional dependencies. ```python !pip install -q /kaggle/input/keras-lib-dataset/keras_nlp-0.9.2-py3-none-any.whl --no-deps ``` -------------------------------- ### Display Sample Prompts with Colorization Source: https://github.com/awsaf49/ai-math-olympiad/blob/main/notebooks/aimo-kerasnlp-starter.ipynb These Python code snippets demonstrate how to select a sample prompt from a list, apply the `colorize_text` function to format it with colors, and then display the formatted prompt using `Markdown()` for visualization. This helps in inspecting the structure and content of individual prompts. ```python # Take a random sample sample = data[12] # Give colors to Instruction, Response and Category sample = colorize_text(sample) # Show sample in markdown display(Markdown(sample)) ``` ```python # Take a random sample sample = data[32] # Give colors to Instruction, Response and Category sample = colorize_text(sample) # Show sample in markdown display(Markdown(sample)) ``` -------------------------------- ### Instantiate Gemma Causal LM from Preset Source: https://github.com/awsaf49/ai-math-olympiad/blob/main/notebooks/aimo-kerasnlp-starter.ipynb Initializes a GemmaCausalLM model using a predefined configuration preset. The summary method is then called to display the model architecture and parameter count. ```python gemma_lm = keras_nlp.models.GemmaCausalLM.from_preset(CFG.preset) gemma_lm.summary() ``` -------------------------------- ### Python: Inferring Gemma Model Before Fine-Tuning Source: https://github.com/awsaf49/ai-math-olympiad/blob/main/notebooks/aimo-kerasnlp-starter.ipynb This code snippet demonstrates how to generate a prompt using a template and then use the Gemma language model to infer a response. It takes a sample from a DataFrame, formats a prompt with a problem, generates output from the model, colorizes the text, and displays it in markdown. This is done before fine-tuning to observe initial model behavior. ```python # Take one sample row = df.iloc[12] # Generate Prompt using template prompt = template.format( problem=row.problem, solution="", ) # Infer output = gemma_lm.generate(prompt, max_length=1024) # Colorize output = colorize_text(output) # Display in markdown display(Markdown(output)) ``` ```python # Take one sample row = df.iloc[32] # Generate Prompt using template prompt = template.format( problem=row.problem, solution="" ) # Infer output = gemma_lm.generate(prompt, max_length=1024) # Colorize output = colorize_text(output) # Display in markdown display(Markdown(output)) ``` -------------------------------- ### Load and Prepare Training Data Source: https://github.com/awsaf49/ai-math-olympiad/blob/main/notebooks/aimo-kerasnlp-starter.ipynb Loads training and testing datasets from CSV files, concatenates them, and selects the first 1000 samples for fine-tuning. This step prepares the data for subsequent filtering and processing. ```python df1 = pd.read_csv("/kaggle/input/math-qsa-dataset/train.csv") df2 = pd.read_csv("/kaggle/input/math-qsa-dataset/test.csv") df = pd.concat([df1, df2], axis=0) df = df[:1000] # take first 1000 samples df.head(2) ``` -------------------------------- ### Prompt Template Engineering for Instruction Following Source: https://context7.com/awsaf49/ai-math-olympiad/llms.txt Creates a structured prompt template for instruction-following models. The template defines a role, provides instructions for solving math problems, and specifies the format for problem, solution, and answer sections. ```python template = """Role: You are an advanced AI system with exceptional mathematical reasoning and problem-solving capabilities, specifically designed to solve tricky math problems (whose answer is a non-negative integer) written in LaTeX format from the AI Mathematical Olympiad (AIMO) competition. Your task is to accurately analyze and solve intricate mathematical problems, demonstrating a deep understanding of mathematical concepts and a strong ability to apply logical reasoning strategies. Instruction: 1. Carefully read and comprehend the problem statement provided in the "Problem" section. 2. In the "Solution" section, provide a solution of the problem with detailed explanation of your logical reasoning process. Keep in mind that answer must be a non-negative integer number. 3. At the end, create a "Answer" section where you will state only the final numerical or algebraic answer, without any additional text or narrative. Problem: {problem} Solution: {solution}""" # Generate prompts for training data df["prompt"] = df.apply( lambda row: template.format( problem=row.problem, solution=f"{row.solution}\n\nAnswer:\n{row.answer}" ), axis=1 ) data = df.prompt.tolist() ``` -------------------------------- ### Compile and Train Model (Python) Source: https://context7.com/awsaf49/ai-math-olympiad/llms.txt Configures the model for training by setting the sequence length, loss function, optimizer, and metrics. It then fine-tunes the model on the prepared dataset using specified epochs and batch size. ```python # Limit sequence length for memory efficiency gemma_lm.preprocessor.sequence_length = CFG.sequence_length # Compile with sparse categorical crossentropy loss gemma_lm.compile( loss=keras.losses.SparseCategoricalCrossentropy(from_logits=True), optimizer=keras.optimizers.Adam(learning_rate=2e-5), weighted_metrics=[keras.metrics.SparseCategoricalAccuracy()], ) # Train the model gemma_lm.fit( data, epochs=CFG.epochs, batch_size=CFG.batch_size ) ``` -------------------------------- ### Define Configuration Parameters Source: https://github.com/awsaf49/ai-math-olympiad/blob/main/notebooks/aimo-kerasnlp-starter.ipynb Defines a configuration class 'CFG' to hold various parameters for the project, including random seed, dataset path, pre-trained model preset, sequence length, batch size, and number of training epochs. These parameters control reproducibility and training settings. ```python class CFG: seed = 42 dataset_path = "/kaggle/input/ai-mathematical-olympiad-prize" preset = "gemma_1.1_instruct_2b_en" # name of pretrained Gemma sequence_length = 512 # max size of input sequence for training batch_size = 1 # size of the input batch in training epochs = 1 # number of epochs to train ``` -------------------------------- ### Configure Keras Backend and Environment Source: https://github.com/awsaf49/ai-math-olympiad/blob/main/notebooks/aimo-kerasnlp-starter.ipynb Sets the Keras backend to JAX for optimal performance and configures environment variables to manage memory fragmentation. It also imports essential libraries for Keras, KerasNLP, numerical operations, data manipulation, progress bars, and plotting. ```python import os os.environ["KERAS_BACKEND"] = "jax" # you can also use tensorflow or torch os.environ["XLA_PYTHON_CLIENT_MEM_FRACTION"] = "0.9" # avoid memory fragmentation on JAX backend. import keras import keras_nlp import numpy as np import pandas as pd from tqdm.notebook import tqdm tqdm.pandas() # progress bar for pandas import plotly.graph_objs as go import plotly.express as px from IPython.display import display, Markdown ``` -------------------------------- ### Format Prompts from DataFrame Source: https://github.com/awsaf49/ai-math-olympiad/blob/main/notebooks/aimo-kerasnlp-starter.ipynb This Python code snippet demonstrates how to format prompts using a predefined template and a Pandas DataFrame. It iterates through each row of the DataFrame, formatting the 'problem', 'solution', and 'answer' columns into a complete prompt, and then converts the prompts into a list. ```python df["prompt"] = df.progress_apply(lambda row: template.format(problem=row.problem, solution=f"{row.solution}\n\nAnswer:\n{row.answer}"), axis=1) data = df.prompt.tolist() ``` -------------------------------- ### Python: Inferring Gemma Model After Fine-Tuning Source: https://github.com/awsaf49/ai-math-olympiad/blob/main/notebooks/aimo-kerasnlp-starter.ipynb This code snippet demonstrates inference using the Gemma model after it has been fine-tuned with LoRA. Similar to the pre-fine-tuning inference, it takes a sample, generates a prompt, infers the output, colorizes the text, and displays it in markdown. This allows for a comparison of the model's responses before and after fine-tuning. ```python # Take one sample row = df.iloc[12] # Generate Prompt using template prompt = template.format( problem=row.problem, solution="" ) # Infer output = gemma_lm.generate(prompt, max_length=1024) # Colorize output = colorize_text(output) # Display in markdown display(Markdown(output)) ``` ```python # Take one sample row = df.iloc[32] # Generate Prompt using template prompt = template.format( problem=row.problem, solution="" ) # Infer output = gemma_lm.generate(prompt, max_length=1024) # Colorize output = colorize_text(output) # Display in markdown display(Markdown(output)) ``` -------------------------------- ### Preprocessing Text with KerasNLP Tokenizer Source: https://context7.com/awsaf49/ai-math-olympiad/llms.txt Demonstrates how KerasNLP preprocesses raw text into token IDs and padding masks, which are required inputs for the model. It also shows how the target labels (next token) and sample weights are generated for causal language model training. ```python # Preprocess raw text into model-ready format x, y, sample_weight = gemma_lm.preprocessor(data[0:2]) # x contains: token_ids and padding_mask # y contains: next token labels for causal LM training # sample_weight: weights for loss computation # Display preprocessed shapes for k, v in x.items(): print(k, ":", v.shape) # Output: # token_ids : (2, 512) # padding_mask : (2, 512) ``` -------------------------------- ### Prepare Submission File (Python) Source: https://github.com/awsaf49/ai-math-olympiad/blob/main/notebooks/aimo-kerasnlp-starter.ipynb This Python code prepares the submission file for the AIMO competition. It takes the test predictions, formats them into a pandas DataFrame with 'id' and 'answer' columns, and saves it as `submission.csv`. The answers are expected to be between 0-999, a requirement handled during the inference stage by the `get_answer` function's modulo operation. ```python import pandas as pd # Assuming test_preds is generated from infer function # test_preds = [...] sub_df = pd.DataFrame(test_preds, columns=["id", "answer"]) sub_df.to_csv("submission.csv", index=False, header=True) sub_df.head() ``` -------------------------------- ### Python: Compiling and Training Gemma Model with LoRA Source: https://github.com/awsaf49/ai-math-olympiad/blob/main/notebooks/aimo-kerasnlp-starter.ipynb This code snippet configures the Gemma model for training after enabling LoRA. It sets the input sequence length, compiles the model with a specified loss function (SparseCategoricalCrossentropy), optimizer (Adam), and metric (SparseCategoricalAccuracy), and then trains the model for a set number of epochs and batch size. This prepares the model for improved performance on the target task. ```python # Limit the input sequence length to 512 (to control memory usage). gemma_lm.preprocessor.sequence_length = CFG.sequence_length # Compile the model with loss, optimizer, and metric gemma_lm.compile( loss=keras.losses.SparseCategoricalCrossentropy(from_logits=True), optimizer=keras.optimizers.Adam(learning_rate=2e-5), weighted_metrics=[keras.metrics.SparseCategoricalAccuracy()], ) # Train model gemma_lm.fit(data, epochs=CFG.epochs, batch_size=CFG.batch_size) ``` -------------------------------- ### Create Submission File (Python) Source: https://context7.com/awsaf49/ai-math-olympiad/llms.txt Generates the final submission CSV file required for Kaggle competitions. This involves running inference on the test data and formatting the predictions into the specified submission structure. ```python # Load test data test_df = pd.read_csv(f"{CFG.dataset_path}/test.csv") # Run inference on test data test_preds = infer(test_df) # Create submission dataframe # Note: Answers are already constrained to 0-999 via modulo in get_answer() sub_df = pd.DataFrame(test_preds, columns=["id", "answer"]) # Save submission file sub_df.to_csv("submission.csv", index=False, header=True) print(sub_df.head()) ``` -------------------------------- ### Colorize Prompt Text for Visualization Source: https://github.com/awsaf49/ai-math-olympiad/blob/main/notebooks/aimo-kerasnlp-starter.ipynb This Python function, `colorize_text`, takes a string as input and adds markdown formatting to colorize specific keywords ('Role', 'Instruction', 'Problem', 'Solution', 'Answer') for better visual distinction. This is useful for rendering prompts in a more readable format, especially when displayed as markdown. ```python def colorize_text(text): for word, color in zip(["Role", "Instruction", "Problem", "Solution", "Answer"], ["blue", "yellow", "red", "cyan", "green"]): text = text.replace(f"{word}:", f"\n\n**{word}:**") return text ``` -------------------------------- ### Loading Gemma Causal Language Model with KerasNLP Source: https://context7.com/awsaf49/ai-math-olympiad/llms.txt Loads a pretrained Gemma model using KerasNLP's `from_preset` method. It supports various Gemma presets for causal language modeling and displays the model summary, showing approximately 2.5 billion parameters. ```python # Load pretrained Gemma model # Available presets: # - gemma_2b_en (Pretrained, 2B params) # - gemma_1.1_instruct_2b_en (Instruction tuned, 2B params) # - gemma_7b_en (Pretrained, 7B params) # - gemma_1.1_instruct_7b_en (Instruction tuned, 7B params) # - code_gemma_2b_en (Code completion, 2B params) # - code_gemma_7b_en (Code completion, 7B params) gemma_lm = keras_nlp.models.GemmaCausalLM.from_preset(CFG.preset) gemma_lm.summary() # Output shows model architecture with ~2.5 billion parameters ``` -------------------------------- ### Python: Enabling LoRA for Gemma Model Fine-Tuning Source: https://github.com/awsaf49/ai-math-olympiad/blob/main/notebooks/aimo-kerasnlp-starter.ipynb This code snippet enables Low Rank Adaptation (LoRA) for the Gemma model with a specified rank and then prints the model's summary. LoRA is used to efficiently fine-tune large language models by injecting trainable rank-decomposition matrices. This step significantly reduces the number of trainable parameters, saving memory. ```python # Enable LoRA for the model and set the LoRA rank to 4. gemma_lm.backbone.enable_lora(rank=4) gemma_lm.summary() ``` -------------------------------- ### Enable LoRA for Parameter-Efficient Fine-Tuning (Python) Source: https://context7.com/awsaf49/ai-math-olympiad/llms.txt Enables Low-Rank Adaptation (LoRA) for parameter-efficient fine-tuning, significantly reducing the number of trainable parameters while aiming to preserve model quality. This involves injecting trainable rank-decomposition matrices into the model's architecture. ```python # Enable LoRA with rank 4 # Higher rank = more detailed changes but more trainable parameters gemma_lm.backbone.enable_lora(rank=4) gemma_lm.summary() # Before LoRA: ~2.5 billion trainable parameters # After LoRA: ~1.3 million trainable parameters # LoRA injects trainable rank-decomposition matrices A (d×r) and B (r×d) # New output = (W0·x + b0) + (B·A·x) where r << d ``` -------------------------------- ### Preprocess Input Data for Gemma Source: https://github.com/awsaf49/ai-math-olympiad/blob/main/notebooks/aimo-kerasnlp-starter.ipynb Uses the model's internal preprocessor to convert raw string data into tokenized tensors. The output includes token IDs and padding masks necessary for model training or inference. ```python x, y, sample_weight = gemma_lm.preprocessor(data[0:2]) # Display the shape of each processed output for k, v in x.items(): print(k, ":", v.shape) ``` -------------------------------- ### Generate Baseline Text Responses (Python) Source: https://context7.com/awsaf49/ai-math-olympiad/llms.txt Generates responses from the base language model before fine-tuning to establish a performance baseline. It takes a sample problem, formats it into a prompt, and uses the model to generate output. Note that responses may be inaccurate before fine-tuning. ```python # Take a sample problem row = df.iloc[12] # Generate prompt (with empty solution for inference) prompt = template.format( problem=row.problem, solution="" ) # Generate response using the base model output = gemma_lm.generate(prompt, max_length=1024) # Display output (note: responses may be inaccurate before fine-tuning) print(output) ``` -------------------------------- ### Data Loading and Filtering with Pandas Source: https://context7.com/awsaf49/ai-math-olympiad/llms.txt Loads and merges datasets from CSV files, then filters for samples with non-negative integer answers, which are required for the AIMO competition. It uses Pandas for data manipulation. ```python # Load and merge datasets df1 = pd.read_csv("/kaggle/input/math-qsa-dataset/train.csv") df2 = pd.read_csv("/kaggle/input/math-qsa-dataset/test.csv") df = pd.concat([df1, df2], axis=0) df = df[:1000] # Take first 1000 samples for faster training # Filter for non-negative integer answers only def is_integer(text): try: if int(text) >= 0: return True else: return False except ValueError: return False df["is_integer"] = df.answer.map(is_integer) df = df[df.is_integer].reset_index(drop=True) # Expected columns: problem, solution, answer, level, type print(df.head(2)) ``` -------------------------------- ### Define AI Math Olympiad Prompt Template Source: https://github.com/awsaf49/ai-math-olympiad/blob/main/notebooks/aimo-kerasnlp-starter.ipynb This Python code defines a string template for generating prompts for an AI model. The template includes a role, instructions, and placeholders for the problem, solution, and answer, ensuring the AI adheres to the required output format. ```python template = """Role:\nYou are an advanced AI system with exceptional mathematical reasoning and problem-solving capabilities, specifically designed to solve tricky math problems (whose answer is a non-negative integer) written in LaTeX format from the AI Mathematical Olympiad (AIMO) competition. Your task is to accurately analyze and solve intricate mathematical problems, demonstrating a deep understanding of mathematical concepts and a strong ability to apply logical reasoning strategies.\n\nInstruction:\n1. Carefully read and comprehend the problem statement provided in the "Problem" section.\n2. In the "Solution" section, provide a solution of the problem with detailed explanation of your logical reasoning process. Keep in mind that answer must be a non-negative integer number.\n3. At the end, create a "Answer" section where you will state only the final numerical or algebraic answer, without any additional text or narrative.\n\nProblem:\n{problem}\n\nSolution:\n{solution}""" ``` -------------------------------- ### Generate Text Responses After Fine-Tuning (Python) Source: https://context7.com/awsaf49/ai-math-olympiad/llms.txt Generates improved responses from the fine-tuned model, demonstrating enhanced instruction-following capabilities. It uses the same sample problem and prompt as the baseline generation but leverages the updated model for more accurate and structured output. ```python # Take the same sample problem row = df.iloc[12] # Generate prompt prompt = template.format( problem=row.problem, solution="" ) # Generate response from fine-tuned model output = gemma_lm.generate(prompt, max_length=1024) # Model now follows instructions more accurately and provides # structured Problem -> Solution -> Answer responses print(output) ``` -------------------------------- ### Inference on AIMO Training Data (Python) Source: https://github.com/awsaf49/ai-math-olympiad/blob/main/notebooks/aimo-kerasnlp-starter.ipynb This Python code snippet demonstrates how to perform inference on the AIMO training dataset. It reads the `train.csv` file into a pandas DataFrame and then uses the `infer` function to generate predictions. The resulting predictions are stored in a new DataFrame, including the ID, predicted answer, and the actual answer. ```python import pandas as pd # Assuming CFG and infer function are defined elsewhere # CFG = ... # def infer(df): # ... aimo_df = pd.read_csv(f"{CFG.dataset_path}/train.csv") train_preds = infer(aimo_df) train_pred_df = pd.DataFrame(train_preds, columns=["id", "prediction", "answer"]) train_pred_df.head() ``` -------------------------------- ### Answer Extraction and Inference Pipeline (Python) Source: https://context7.com/awsaf49/ai-math-olympiad/llms.txt Implements a pipeline for extracting numerical answers from model responses and running batch inference on competition data. It includes functions to parse answers from text and process a dataframe of problems. ```python import re def get_answer(text): """Extract non-negative integer answer from model response.""" try: answer = re.search(r'Answer:\s*([\s\S]+)', text).group(1).strip() answer = answer.replace(",", "") if is_integer(answer): return int(answer) % 1000 # AIMO requires answers 0-999 else: return 0 except: return 0 def infer(df): """Run inference on a dataframe of problems.""" preds = [] for i in range(len(df)): row = df.iloc[i] # Generate prompt prompt = template.format( problem=row.problem, solution="" ) # Generate response output = gemma_lm.generate(prompt, max_length=1024) pred = get_answer(output) # Store predictions preds.append([row.id, pred]) if "answer" in row: preds[-1] += [row.answer] return preds # Run inference on AIMO competition data aimo_df = pd.read_csv(f"{CFG.dataset_path}/train.csv") train_preds = infer(aimo_df) train_pred_df = pd.DataFrame(train_preds, columns=["id", "prediction", "answer"]) print(train_pred_df) ``` -------------------------------- ### Python: Importing Regular Expression Module Source: https://github.com/awsaf49/ai-math-olympiad/blob/main/notebooks/aimo-kerasnlp-starter.ipynb This code snippet imports the regular expression module in Python. This module provides support for regular expressions, which are sequences of characters that define a search pattern. It is often used for string matching and manipulation, such as parsing or validating text data. ```python import re ``` -------------------------------- ### Set Random Seed for Reproducibility Source: https://github.com/awsaf49/ai-math-olympiad/blob/main/notebooks/aimo-kerasnlp-starter.ipynb Ensures reproducibility of results by setting the random seed for Keras. This allows for consistent outcomes across multiple runs of the training process. ```python keras.utils.set_random_seed(CFG.seed) ``` -------------------------------- ### Infer on AIMO Test Data (Python) Source: https://github.com/awsaf49/ai-math-olympiad/blob/main/notebooks/aimo-kerasnlp-starter.ipynb This code snippet performs inference on the AIMO test dataset. It reads the `test.csv` file into a pandas DataFrame and then utilizes the `infer` function to obtain predictions. The output of the `infer` function, containing the IDs and predicted answers, is stored in the `test_preds` variable. ```python import pandas as pd # Assuming CFG and infer function are defined elsewhere # CFG = ... # def infer(df): # ... test_df = pd.read_csv(f"{CFG.dataset_path}/test.csv") test_preds = infer(test_df) ``` -------------------------------- ### Perform Inference on DataFrame (Python) Source: https://github.com/awsaf49/ai-math-olympiad/blob/main/notebooks/aimo-kerasnlp-starter.ipynb The `infer` function processes a pandas DataFrame to generate predictions. It iterates through each row, constructs a prompt using a template, and uses a language model (`gemma_lm`) to generate an output. The `get_answer` function is then used to extract the prediction from the output. Predictions are stored along with the problem ID and, if available, the actual answer. ```python from tqdm import tqdm import pandas as pd # Assuming template, gemma_lm, and CFG are defined elsewhere # template = "..." # gemma_lm = ... # CFG = ... def infer(df): preds = [] for i in tqdm(range(len(df))): row = df.iloc[i] # Generate Prompt using template prompt = template.format( problem=row.problem, solution="" ) # Infer output = gemma_lm.generate(prompt, max_length=1024) pred = get_answer(output) # Store predictions preds.append([row.id, pred]) if "answer" in row: preds[-1] += [row.answer] return preds ``` -------------------------------- ### Extract Answer from Model Response (Python) Source: https://github.com/awsaf49/ai-math-olympiad/blob/main/notebooks/aimo-kerasnlp-starter.ipynb This Python function, `get_answer`, extracts a numerical answer from a given text. It uses regular expressions to find the answer, cleans it by removing commas, and converts it to an integer. If the answer is an integer, it returns the answer modulo 1000; otherwise, it returns 0. This function is crucial for parsing the output of language models. ```python import re def is_integer(s): try: int(s) return True except ValueError: return False def get_answer(text): try: answer = re.search(r'Answer:\s*([\s\S]+)', text).group(1).strip() answer = answer.replace(",", "") if is_integer(answer): return int(answer) % 1000 else: return 0 except: return 0 ``` -------------------------------- ### Filter Data for Non-Negative Integer Answers Source: https://github.com/awsaf49/ai-math-olympiad/blob/main/notebooks/aimo-kerasnlp-starter.ipynb Filters the dataset to include only problems with non-negative integer answers. A helper function 'is_integer' checks if the answer can be converted to a non-negative integer. This ensures the data aligns with the competition's requirements. ```python def is_integer(text): try: if int(text) >= 0: return True else: return False except ValueError: return False df["is_integer"] = df.answer.map(is_integer) df = df[df.is_integer].reset_index(drop=True) df.head(2) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.