Skip to content

Instantly share code, notes, and snippets.

@tqlong
tqlong / Chuẩn bị dữ liệu.py
Created May 13, 2025 06:18
Ví dụ CRF và NLTK
import nltk
from nltk.corpus import treebank
# Tải dữ liệu treebank
nltk.download('treebank')
tagged_sentences = treebank.tagged_sents()
# Chia dữ liệu thành tập huấn luyện và tập kiểm tra
train_size = int(0.8 * len(tagged_sentences))
train_sents = tagged_sentences[:train_size]
@tqlong
tqlong / Khai báo thư viện.py
Created May 13, 2025 03:20
Ví dụ GAN cho MNIST
import torch
import torch.nn as nn
import torch.optim as optim
import numpy as np
import matplotlib.pyplot as plt
@tqlong
tqlong / Chuẩn bị dữ liệu.py
Created May 13, 2025 02:45
Ví dụ PCA trên CIFAR-10
import numpy as np
import matplotlib.pyplot as plt
from sklearn.decomposition import PCA
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score
from tensorflow.keras.datasets import cifar10
(x_train, y_train), (x_test, y_test) = cifar10.load_data()
print(f"Train data shape: {x_train.shape}")
import xgboost as xgb
import pandas as pd
import numpy as np
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
iris = load_iris()
X = iris.data
y = iris.target
import torch
import torch.nn as nn
class IoULoss(nn.Module):
def __init__(self, num_classes, eps=1e-6):
"""
IoU Loss for multi-class image segmentation.
Args:
- num_classes (int): Number of classes (C).
@tqlong
tqlong / mnist_cnn.py
Created April 9, 2024 05:38
MNIST NLP CNN
import torch
import torch.nn as nn
import torch.optim as optim
from torch.nn.functional import relu, max_pool2d
from torch.utils.data import DataLoader
from torchvision import datasets
from torchvision import transforms as T
from tqdm import tqdm
#include "display.h"
#include "count.h"
#include <iostream>
using namespace std;
void displayWinning()
{
const vector<string> figures = {
" O \n"
// TODO: read all numbers (int, float), separated by comma
// TODO: read a table of numbers from a text file, separated by comma
// TODO: read a table of student information from a text file, separated by comma
// (ten, tuoi, gioi tinh, diem trung binh)
// struct_tutorial.cpp: struct examples
#include <iostream>
#include <vector>
#include <algorithm>
struct Vector {
int x;
int y;
// constructor
@tqlong
tqlong / 01.main-sfml.cpp
Last active December 14, 2022 10:19
TICTACTOE-Graphics-SFML
#include <SFML/Graphics.hpp>
#include <iostream>
#include <vector>
typedef std::vector<char> Row;
typedef std::vector<Row> GameState;
const int SIZE=3;
sf::CircleShape createShape(sf::Texture& texture, int i, int j, char player)
{