Skip to content

Instantly share code, notes, and snippets.

View xiabingquan's full-sized avatar

xiabingquan xiabingquan

View GitHub Profile
@xiabingquan
xiabingquan / visualize_edit_distance.py
Last active December 12, 2022 06:10
Visualize errors of Edit Distance (Insertion, Deletion and Replacement)
from argparse import ArgumentParser
import editdistance
from rich.text import Text
from rich.console import Console
def edit_dist_dp(gt, hyp):
"""
A Dynamic Programming based Python program for edit distance problem
@xiabingquan
xiabingquan / transformer_all_in_one.py
Created December 6, 2023 14:52
Implement Transformer from scratach. All modules included in one file!
# coding=utf-8
# Contact: bingquanxia@qq.com
import numpy as np
import torch
import torch.nn as nn
def get_len_mask(b: int, max_len: int, feat_lens: torch.Tensor, device: torch.device) -> torch.Tensor:
@xiabingquan
xiabingquan / flash_attention_in_numpy.py
Last active June 27, 2024 02:59
An toy example of flash attention implemented with Numpy.
# A minimal exmaple of flash attention implemented in Numpy
# Contact: bingquanxia AT qq.com
import unittest
from typing import List
import numpy as np
import torch