1. Trang chủ
  2. » Giáo Dục - Đào Tạo

Xử lý ngôn ngữ tự nhiên đề tàiphân loại bình luận

44 7 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Nội dung

Xử lý ngơn ngữ tự nhiên Đề tài:Phân loại bình luận GVHD: Đặng Thị Phúc SVTH: Lê Đình Hiếu 17030181 Mai Văn Hưng 17081211 Nguyễn Chí khang 17048731 TIEU LUAN MOI download : skknchat@gmail.com MỤC LỤC CHƯƠNG Giới thiệu Đề Tài .3 CHƯƠNG Các thư viện sử dụng CHƯƠNG Website sử dụng để cào liệu CHƯƠNG Tiền xử lý liệu 11 CHƯƠNG Word embedding 15 CHƯƠNG Model building 16 CHƯƠNG Đánh giá model 40 CHƯƠNG Tài liệu tham khảo41 TIEU LUAN MOI download : skknchat@gmail.com CHƯƠNG GIỚI THIỆU ĐỀ TÀI Giới thiệu Đánh giá bình luận đồ ăn, dựa vào đánh giá bình luận khách hàng đồ ăn, thông qua website người làm dịch vụ Từ đưa sửa đổi, cải thiện chất lượng sản phẩm để phát triển dịch vụ cá nhân, doanh nghiệp Tuy nhiên, việc đánh giá bình luận đồ ăn theo truyền thống sử dụng nguồn nhân lực người, từ tổng hợp đưa sách, kế hoạch cụ thể Từ nhà lập trình viên áp dụng deep learning NLP vào việc phân loại đánh giá sản phẩm NLP ? Lập trình ngơn ngữ tư NLP cách tiếp cận giả khoa học giao tiếp, phát triển cá nhân tâm lý trị liệu tạo Richard Bandler John Gri California, Hoa Kỳ vào năm 1970 Những người sáng tạo NLP tuyên bố có mối liên hệ trình thần kinh (neuro), ngơn ngữ (linguistic) mơ hình hành vi học thơng qua kinh nghiệm (programming) hay viết tắt gọi ngôn ngữ NLP Và điều thay đổi để đạt mục tiêu cụ thể sống Bandler Gri nói phương pháp NLP “mơ hình hóa” kỹ người đặc biệt, cho phép học kỹ Họ cho biết thêm, NLP điều trị vấn đề ám ảnh, trầm cảm, hội chứng tic, bệnh tâm lý, dị ứng rối loạn học tập Hiểu cách đơn giản, xử lý ngôn ngữ tự nhiên (NLP) cho phép bạn làm thiên tài, chuyên gia, người thành cơng,… làm cách “lập trình” não theo việc cài đặt não họ Ứng dụng NLP Phương pháp NLP ứng dụng nhiều ngành nghề khác bao gồm trị liệu, giáo dục, kinh doanh,… 3.1 Ứng dụng NLP trị liệu NLP sử dụng liệu pháp bổ trợ nhà trị liệu thực hành chuyên ngành trị liệu khác Ngồi ra, coi phương pháp điều trị đặc hiệu gọi “Neurolinguistic Psychotherapy” công nhận Hội đồng Tâm lý Vương quốc Anh TIEU LUAN MOI download : skknchat@gmail.com Phương pháp sử dụng để nghiên cứu ảnh hưởng niềm tin bệnh tật Và nhà khoa học nhận thấy cách bác sĩ trao đổi thơng tin với bệnh nhân ảnh hưởng tốt xấu trình phục hồi Từ tạm đưa kết luận rằng, niềm tin có mối tương quan thuận sức khỏe thể chất người 3.2 Ứng dụng khác Mặc dù kỹ thuật cốt lõi ban đầu NLP trị liệu theo định hướng chất chung chúng cho phép chúng áp dụng cho lĩnh vực khác Kỹ thuật phát huy tiềm nlp ứng dụng vào: - Thuyết phục Bán hàng Đàm phán Đào tạo quản lý Thể thao Giảng dạy Huấn luyện Xây dựng đội ngũ TIEU LUAN MOI download : skknchat@gmail.com CHƯƠNG Thư viện để cào liệu CÁC THƯ VIỆN SỬ DỤNG - Thư viện Beautiful Soup: BeautifulSoup thư viện Python dùng để lấy liệu khỏi file HTML XML Nó hoạt động với parser (trình phân tích cú pháp) cung cấp cho bạn cách để điều hướng, tìm kiếm chỉnh sửa parse tree (cây phân tích tạo từ parser) Nhờ parser giúp lập trình viên tiết kiệm nhiều làm việc - Thư viện Requests Requests mơ-đun Python mà bạn sử dụng để gửi tất loại yêu cầu HTTP Đây thư viện dễ sử dụng với nhiều tính khác nhau, từ việc truyền tham số URL gửi header tùy biến Xác minh SSL Trong hướng dẫn này, bạn học cách sử dụng thư viện requests để gửi yêu cầu HTTP đơn giản Python TIEU LUAN MOI download : skknchat@gmail.com - - Thư viện tiền xử lý liệu Thư viện re Biểu thức quy (Regular Expressions) hay Regex Python định nghĩa chuỗi ký tự sử dụng để tìm kiếm mẫu chuỗi Mơđun re cung cấp hỗ trợ để sử dụng regex chương trình python Mơ-đun re bắn ngoại lệ có lỗi xảy sử dụng biểu thức quy Thư viện Pandas Pandas thư viện Python cung cấp cấu trúc liệu nhanh, mạnh mẽ, linh hoạt mang hàm ý Tên thư viện bắt nguồn từ panel data (bảng liệu) Pandas thiết kế để làm việc dễ dàng trực quan với liệu có cấu trúc (dạng bảng, đa chiều, có tiềm khơng đồng nhất) liệu chuỗi thời gian TIEU LUAN MOI download : skknchat@gmail.com - Thư viện numpy Numpy (Numeric Python): thư viện toán học phổ biến mạnh mẽ Python Cho phép làm việc hiệu với ma trận mảng, đặc biệt liệu ma trận mảng lớn với tốc độ xử lý nhanh nhiều lần sử dụng “core Python” đơn - Thư viện String Thư viện underthesea Underthesea mô-đun, liệu hướng dẫn Python mã nguồn mở hỗ trợ nghiên cứu phát triển Xử lý ngôn ngữ tự nhiên tiếng Việt Ở đồ án này, thư viện underthesea sử dụng việc tách từ - Thư viện để tạo model word embedding Thư viện FastText TIEU LUAN MOI download : skknchat@gmail.com FastText, xây dựng Word2Vec cách học biểu diễn vectơ cho từ n-gram tìm thấy từ Các giá trị biểu diễn sau tính trung bình thành vectơ bước đào tạo Trong điều bổ sung nhiều tính tốn bổ sung cho việc đào tạo, cho phép nhúng từ để mã hóa thơng tin từ phụ Các vectơ FastText chứng minh xác vectơ Word2Vec số biện pháp khác - Thư viện để build model Thư viện Scikit-learn Scikit-learn (Sklearn) thư viện mạnh mẽ dành cho thuật toán học máy viết ngôn ngữ Python Thư viện cung cấp tập cơng cụ xử lý tốn machine learning statistical modeling gồm: classification, regression, clustering, dimensionality reduction TIEU LUAN MOI download : skknchat@gmail.com - - Thư viện Keras Keras open source cho Neural Network viết ngơn ngữ Python Keras sử dụng chung với thư viện tiếng Tensorflow, CNTK, Theano Một số ưu điểm Keras như: Dễ sử dụng, dùng đơn giản Tensor, xây dựng model nhanh Thư viện vẽ model để đánh giá model Thư viện Matplotlib Matplotlib thư viện vẽ đồ thị cho ngơn ngữ lập trình Python phần mở rộng tốn học số NumPy Nó cung cấp API hướng đối tượng để nhúng lô vào ứng dụng cách sử dụng công cụ GUI cho mục đích chung Tkinter, wxPython, Qt GTK + TIEU LUAN MOI download : skknchat@gmail.com CHƯƠNG WEBSITE SỬ DỤNG ĐỂ CÀO DỮ LIỆU Sử dụng Foody.vn Được xây dựng từ năm 2012 TP HCM, Việt Nam, Foody cộng đồng tin cậy cho người tìm kiếm, đánh giá, bình luận địa điểm ăn uống: nhà hàng, quán ăn, cafe, bar, karaoke, tiệm bánh, khu du lịch Việt Nam - từ website ứng dụng di động Tất thành viên từ Bắc đến Nam, Foody kết nối thực khách đến với địa điểm ăn uống lớn nhỏ đất nước Đến thời điểm tại, Foody với hàng trăm ngàn địa điểm hàng trăm ngàn bình luận, hình ảnh Việt Nam, hầu hết tỉnh thành Foody cách dễ để bạn tìm kiếm lựa chọn địa điểm tốt cho bạn bè Sử dụng khu vực để cào liệu Hà Nội https://www.foody.vn/ha-noi TIEU LUAN MOI download : skknchat@gmail.com Attension Model class Attention(tf.keras.Model): def init (self, units): super(Attention, self). init () self.W1 = tf.keras.layers.Dense(units) self.W2 = tf.keras.layers.Dense(units) self.V = tf.keras.layers.Dense(1) def call(self, features, hidden): # hidden shape == (batch_size, hidden size) # hidden_with_time_axis shape == (batch_size, 1, hidden size) TIEU LUAN MOI download : skknchat@gmail.com # we are doing this to perform addition to calculate the score hidden_with_time_axis = tf.expand_dims(hidden, 1) # score shape == (batch_size, max_length, 1) # we get at the last axis because we are applying score to self.V # the shape of the tensor before applying self.V is (batch_size, max_length, units) score = tf.nn.tanh( self.W1(features) + self.W2(hidden_with_time_axis)) # attention_weights shape == (batch_size, max_length, 1) attention_weights = tf.nn.softmax(self.V(score), axis=1) # context_vector shape after sum == (batch_size, hidden_size) context_vector = attention_weights * features context_vector = tf.reduce_sum(context_vector, axis=1) return context_vector, attention_weights from keras.layers import Concatenate, Dense, Input, LSTM, Embedding, Dropout, Activa tion, GRU, Flatten model4 = keras.Sequential() sequence_input = Input(shape=(max_len,), dtype="int32") embedded_sequences = Embedding(vocab_size, embedding_dim)(sequence_input) lstm = Bidirectional(LSTM(32, return_sequences = True), name="bi_lstm_0") (embedded_sequences) # Getting our LSTM outputs (lstm, forward_h, forward_c, backward_h, backward_c) = Bidirectional(LSTM(32, return _sequences=True, return_state=True), name="bi_lstm_1")(lstm) state_h = Concatenate()([forward_h, backward_h]) state_c = Concatenate()([forward_c, backward_c]) context_vector, attention_weights = Attention(10)(lstm, state_h) # Removal of the globalMaxPool1D could be trouble #globmax = GlobalMaxPool1D()(context_vector) dense1 = Dense(20, activation="relu")(context_vector) dropout = Dropout(0.05)(dense1) output = Dense(9, activation="softmax")(dropout) TIEU LUAN MOI download : skknchat@gmail.com model4 = model4.add(keras.Model(inputs=sequence_input, outputs=output)) train_history4 = model4.fit(X_train, y_train, batch_size=32, epochs=30, validation_data= (X_test, y_test)) TIEU LUAN MOI download : skknchat@gmail.com Model - Transformer class TransformerBlock(Layer): def init (self, embed_dim, num_heads, ff_dim, rate=0.1): TIEU LUAN MOI download : skknchat@gmail.com super(TransformerBlock, self). init () self.att = MultiHeadAttention(num_heads=num_heads, key_dim=embed_dim) self.ffn = Sequential( [Dense(ff_dim, activation="relu"), Dense(embed_dim),] ) self.layernorm1 = LayerNormalization(epsilon=1e-6) self.layernorm2 = LayerNormalization(epsilon=1e-6) self.dropout1 = Dropout(rate) self.dropout2 = Dropout(rate) def call(self, inputs, training): attn_output = self.att(inputs, inputs) attn_output = self.dropout1(attn_output, training=training) out1 = self.layernorm1(inputs + attn_output) ffn_output = self.ffn(out1) ffn_output = self.dropout2(ffn_output, training=training) return self.layernorm2(out1 + ffn_output) class TokenAndPositionEmbedding(Layer): def init (self, maxlen, vocab_size, embed_dim): super(TokenAndPositionEmbedding, self). init () self.token_emb = Embedding(input_dim=vocab_size, output_dim=embed_dim) self.pos_emb = Embedding(input_dim=maxlen, output_dim=embed_dim) def call(self, x): maxlen = tf.shape(x)[-1] positions = tf.range(start=0, limit=maxlen, delta=1) positions = self.pos_emb(positions) x = self.token_emb(x) return x + positions from keras.layers import GlobalAveragePooling1D from keras.models import Sequential, Model Model Transformers embed_dim = 64 # Embedding size for each token TIEU LUAN MOI download : skknchat@gmail.com num_heads = # Number of attention heads ff_dim = 64 # Hidden layer size in feed forward network inside transformer inputs = Input(shape=(max_len,)) embedding_layer = TokenAndPositionEmbedding(max_len, vocab_size, embed_dim) x = embedding_layer(inputs) transformer_block = TransformerBlock(embed_dim, num_heads, ff_dim) x = transformer_block(x) x = GlobalAveragePooling1D()(x) x = Dropout(0.1)(x) x = Dense(20, activation="relu")(x) x = Dropout(0.1)(x) outputs = Dense(9, activation="softmax")(x) model5 = Model(inputs=inputs, outputs=outputs) TIEU LUAN MOI download : skknchat@gmail.com train_history5 = model5.fit(X_train, y_train, batch_size=32, epochs=50, validation_data= (X_test, y_test)) Model Transformers embed_dim = 64 # Embedding size for each token TIEU LUAN MOI download : skknchat@gmail.com num_heads = # Number of attention heads ff_dim = 64 # Hidden layer size in feed forward network inside transformer inputs = Input(shape=(max_length,)) embedding_layer = TokenAndPositionEmbedding(max_length, vocab_size, embed_dim) x = embedding_layer(inputs) transformer_block = TransformerBlock(embed_dim, num_heads, ff_dim) x = transformer_block(x) x = GlobalAveragePooling1D()(x) x = Dropout(0.5)(x) x = Dense(128, activation="relu")(x) x = Dropout(0.2)(x) x = Dense(64, activation="relu")(x) outputs = Dense(9, activation="softmax")(x) model = Model(inputs=inputs, outputs=outputs) TIEU LUAN MOI download : skknchat@gmail.com Accuracy and loss TIEU LUAN MOI download : skknchat@gmail.com Model Transformers embed_dim = 128 # Embedding size for each token num_heads = # Number of attention heads ff_dim = 128 # Hidden layer size in feed forward network inside transformer inputs = Input(shape=(max_length,)) embedding_layer = TokenAndPositionEmbedding(max_length, vocab_size, embed_dim) x = embedding_layer(inputs) transformer_block = TransformerBlock(embed_dim, num_heads, ff_dim) x = transformer_block(x) x = GlobalAveragePooling1D()(x) x = Dropout(0.1)(x) x = Dense(128, activation="relu")(x) x = Dropout(0.1)(x) x = Dense(64, activation="relu")(x) outputs = Dense(9, activation="softmax")(x) model2 = Model(inputs=inputs, outputs=outputs) TIEU LUAN MOI download : skknchat@gmail.com Accuracy and Loss TIEU LUAN MOI download : skknchat@gmail.com CHƯƠNG ĐÁNH GIÁ MODEL Dựa vào accuray loss model, nói model transformers tốt có thời gian train nhanh nhất, model transformers ổn định Do model transformers model cuối TIEU LUAN MOI download : skknchat@gmail.com TIEU LUAN MOI download : skknchat@gmail.com Tài liệu tham khảo https://fasttext.cc/docs/en/python-module.html https://www.phamduytung.com/blog/2019-05-05-deep-learning-dropout/ https://coggle.it/diagram/WUHhi8EQawABBssa/t/wsd-using-a-bidirectional-lstm https://viblo.asia/p/deploy-ung-dung-machine-learning-len-web-server-phan-4-dubao-gia-coin-voi-lstm-keras-python-Do754JdBZM6 … TIEU LUAN MOI download : skknchat@gmail.com TIEU LUAN MOI download : skknchat@gmail.com ... học kỹ Họ cho biết thêm, NLP điều trị vấn đề ám ảnh, trầm cảm, hội chứng tic, bệnh tâm lý, dị ứng rối loạn học tập Hiểu cách đơn giản, xử lý ngôn ngữ tự nhiên (NLP) cho phép bạn làm thiên tài,... độ xử lý nhanh nhiều lần sử dụng “core Python” đơn - Thư viện String Thư viện underthesea Underthesea mô-đun, liệu hướng dẫn Python mã nguồn mở hỗ trợ nghiên cứu phát triển Xử lý ngôn ngữ tự nhiên. .. TIỀN XỬ LÝ DỮ LIỆU Phân loại sơ data Ta phân loại tạm thời data thành nhãn: - Tào lao - Ngon - Dở - Giá cao - Giá hợp lý - Vệ sinh - Vệ sinh bẩn - Thái độ phục vụ tốt - Thái độ phục vụ tệ Loại

Ngày đăng: 19/07/2022, 15:09

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN

w