Coder Social home page Coder Social logo

basic_classification's Introduction

Train classification model

  1. Dataset định dạng .csv gồm 2 col: product name - tên sản phẩm (sentences) và label - nhãn (labels)

  2. Build the dataset Chạy phần sau để extract data

python build_data.py --data_dir DATA_DIR --data_name FILE.CSV

Chạy xong dữ liệu sẽ tách làm 3 tập train/val/test set cho việc train

  1. Build vocabularies
python build_vocab.py --data_dir data/data_demo --min_count_word 1

Tạo bộ từ điển toàn bộ các từwords.txt và tạo bộ nhãn các danh mục phân loại labels.txt.

  1. File config tuning model: data/config.yaml

  2. Train

python train.py --data_dir DATA_DIR --config_path data/config.yaml --category CATEGORY
  1. Understand model 6.1 Encoder Class:
  • Encoder là một lớp kế thừa từ nn.Module, đại diện cho bộ mã hóa của mô hình. Trong hàm khởi tạo (init), các thông số như kích thước nhãn (label_size), kích thước ẩn (hidden_size), số từ tối đa (max_words), và xác suất dropout (dropout) được thiết lập.
  • Mô hình có hai lớp tuyến tính (layer1 và layer2) với các tham số được khởi tạo và đặt lại trong hàm reset_parameters.
  • Hàm forward định nghĩa quá trình truyển tiếp của mô hình, trong đó các phép toán tuyến tính và hàm kích hoạt ReLU được áp dụng.

6.2 ClassfierModel Class:

  • ClassfierModel là lớp chính của mô hình phân loại. Trong hàm khởi tạo (init), một đối tượng Encoder được tạo ra với các thông số từ tham số đầu vào và được lưu trong biến self.encoder.
  • Hàm preprocess thực hiện xử lý trước dữ liệu đầu vào, chuyển đổi văn bản thành biểu diễn số và tạo tensor text_embeddings.
  • Hàm predict dự đoán nhãn của dữ liệu đầu vào. Nó sử dụng mô hình encoder đã được huấn luyện và trả về danh sách dự đoán và xác suất tương ứng.
  • Hàm encode trả về biểu diễn số của dữ liệu đầu vào, cũng sử dụng mô hình encoder.
  • Hàm preprocess: Hàm này chuyển đổi mỗi đầu vào văn bản thành biểu diễn số bằng cách sử dụng từ điển vocab_dict và các chỉ số của các từ trong từ điển. Các từ không xuất hiện trong từ điển được thay thế bằng chỉ số của từ UNK.
  • Hàm predict: Hàm này đưa ra dự đoán và xác suất tương ứng cho dữ liệu đầu vào, sử dụng mô hình encoder đã được huấn luyện.
  • Hàm encode: Hàm này trả về biểu diễn số của dữ liệu đầu vào, sử dụng mô hình encoder.

basic_classification's People

Contributors

datahuy avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.