1. Trang chủ
  2. » Luận Văn - Báo Cáo

Building a website for selling fashion shoes

100 0 0
Tài liệu đã được kiểm tra trùng lặp

Đ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

Thông tin cơ bản

Tiêu đề Building a website for selling fashion shoes
Tác giả Nguyen Thanh Tuan
Người hướng dẫn Msc. Eng Pham Hai Yen
Trường học Vietnam National University, Hanoi International School
Chuyên ngành Informatics and Computer Engineering
Thể loại Graduation project
Năm xuất bản 2025
Thành phố Hanoi
Định dạng
Số trang 100
Dung lượng 2,41 MB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Cấu trúc

  • CHAPTER 1: OVERVIEW (16)
    • 1.1 General Overview (16)
    • 1.2 Problem Statement (17)
    • 1.3. Technology Stack and Language Selection (19)
      • 1.3.1 NodeJS (19)
      • 1.3.2 Web API (20)
      • 1.3.3 ReactJS (21)
      • 1.3.4. StarUML (22)
      • 1.3.6. AI Application (24)
      • 1.3.7. Technology Improvements (26)
  • CHAPTER 2. ANALYSIS AND SYSTEM DESIGN (28)
    • 2.1. Identifying System Agents and Use Cases (28)
    • 2.2. Use Case Diagrams (31)
    • 2.3. Detailed Use Case Description (37)
      • 2.3.1. Login and Authentication (37)
      • 2.3.3. Search Product (38)
      • 2.3.4 Update Information (39)
      • 2.3.5 Product Comment (39)
      • 2.3.6 Order (40)
      • 2.3.7 Login (41)
      • 2.3.8 Order Management (42)
      • 2.3.9 User Management (43)
      • 2.3.10 Product Management (44)
      • 2.3.11 Category Management (45)
      • 2.3.12. Report View (47)
      • 2.3.13. Report Customer Review (47)
      • 2.3.14. Report ProductView Statistics (48)
    • 2.4. Class Diagram Design Details (48)
    • 2.5. Database Design and Structure (53)
      • 2.5.1. Relational Data diagram (53)
      • 2.5.2. Data of Table Details (53)
  • CHAPTER 3. AI APPLICATION (58)
    • 3.1. AI Model using Colab and API (58)
      • 3.1.1 Technology and Methods (58)
      • 3.1.2 Applications and Algorithms (59)
      • 3.1.3 Model Deployment (61)
      • 3.1.4 Training Method (66)
      • 3.1.5 Performance Evaluation (67)
      • 3.1.6 Benefits, Limitations and Future Work (69)
    • 3.2 Embedded AI (70)
      • 3.2.1 Technology and Methods (70)
      • 3.2.3 Model Deployment (75)
      • 3.2.4 Training Method (76)
      • 3.2.5 Performance Evaluation (77)
      • 3.2.6 Benefits, Limitations, and Future Work (78)
    • 3.3 Improve AI models (79)
      • 3.3.1. Data Preparation and Integration (79)
      • 3.3.2. Algorithm Improvement (80)
      • 3.3.3 Increase Real-Time Behavior Analysis Capability (81)
      • 3.3.4. Implement Recommendation API (81)
  • CHAPTER 4. INSTALLATION AND DEPLOYMENT (82)
    • 4.1. Tools and Installation Environment (82)
      • 4.1.1 XAMPP (82)
      • 4.1.2 Visual Studio Code (83)
    • 4.2. Customer Interface Screens (83)
      • 4.2.1 Login Screen, Registration Screen (83)
      • 4.2.2 Home Page (84)
      • 4.2.4 Shopping Cart, Order, Payment (86)
      • 4.2.5 Favorite Product (89)
      • 4.2.6 Product Search (90)
    • 4.3 Administrator Interface Screen (90)
      • 4.3.1 Category Management (90)
      • 4.3.2 Product Management (91)
      • 4.3.3 Order Management (92)
      • 4.3.4 Revenue Statistics (92)
      • 4.3.5 Customer Reviews (92)
      • 4.3.6 Product View Statistics (93)
    • 4.4. Mobile Optimization and Security Improvements (94)

Nội dung

Building a website for selling fashion shoes Building a website for selling fashion shoes Building a website for selling fashion shoes

OVERVIEW

General Overview

Extensive research has been conducted on the development of online selling websites, examining both local and international perspectives International studies have focused on advanced technologies that enhance the functionality and effectiveness of e-commerce platforms.

AI, data analytics, and mobile-first design are essential for enhancing user experience and optimizing sales processes These technologies facilitate a seamless online shopping environment by providing personalized recommendations, product reviews, and secure payment options.

Research in Vietnam's domestic e-commerce landscape emphasizes the development of platforms that cater to local market needs by incorporating localized payment options and user-friendly features Additionally, enhancing website performance through trust-building activities, such as review systems and mobile compatibility, is a common focus among authors These strategies contribute to the rapid growth of e-commerce in Vietnam, effectively addressing the rising demand for online shopping.

In today's rapidly advancing technological landscape, developing modern e-commerce systems requires a focus on convenience, personalization, and robust data security This project aims to address these critical goals effectively.

• Enhancing user experience through integrating new technology

• Expanding access to international markets by supporting multiple languages

• Improving system performance and security to meet long-term operational requirements

The project aims to build a powerful, flexible system that can be easily expanded in the future.

Problem Statement

The focus of this research is to develop a user-friendly shoe sales website that simplifies the process of searching for and purchasing shoes Given the highly competitive nature of the online shoe market, it is essential for sales websites to adapt to the evolving demands of consumers Presently, many online shoe retailers are encountering significant challenges that hinder their effectiveness in meeting customer expectations.

• Competitions with other sales websites

In today's competitive market for online shoe sales, websites must distinguish themselves by offering unique features and exceptional customer support to attract and retain customers.

With a large number of different shoe models, shoe sales websites need to ensure that products are arranged scientifically and are easy to find

Customers always have high demands on product quality, so websites need to provide complete information about the product so that customers can make accurate purchasing decisions

Online payment is increasingly favored in e-commerce, yet customer concerns about security persist Therefore, sales websites must prioritize safety and security during online transactions Additionally, the platform should offer robust security features and customization options, enabling administrators to manage product information, orders, revenue, and customer data effectively This approach allows businesses to develop targeted marketing strategies, address customer needs, and achieve sustainable growth.

• Apply AI to the website

Integrating AI into a website enhances its intelligence and relevance for users, allowing it to better understand customer preferences and consumption habits This not only streamlines the purchasing process but also fosters customer loyalty, encouraging repeat visits.

AI simplifies the process of collecting and analyzing customer-approved data to identify future trends and improve services For instance, analyzing customer reviews can highlight popular products and potential enhancements Additionally, predictive tools enable accurate demand forecasting, leading to more efficient inventory management and cost savings by minimizing unnecessary expenditures.

Websites equipped with AI features transcend traditional shopping platforms, evolving into hubs for customer networking that boost sales and create competitive challenges for retailers in a crowded marketplace.

During operation, the current system has some major limitations as follows:

1 Product images: Uneven display quality, lack of zoom feature, affecting the shopping experience

2 International accessibility: The website only supports one language, limiting the ability to serve users in other markets

3 Product recommendation personalization: The recommendation algorithms have not made the most of user data, leading to low accuracy

4 Data security: The system lacks some advanced security mechanisms such as two-factor authentication or strong encryption, which can be easily compromised if attacked

5 Mobile interface optimization: The interface on mobile devices has not been fully optimized, reducing the user experience

The above issues directly affect competitiveness and customer satisfaction.

Technology Stack and Language Selection

NodeJS is an open-source, cross-platform JavaScript runtime environment built on Chrome's V8 engine, which enables JavaScript code execution outside of a browser Launched in 2009, NodeJS offers a significant advantage through its support for asynchronous programming, allowing multiple lines of code to be executed simultaneously rather than sequentially, as seen in synchronous programming.

NodeJS is a powerful platform based on Chrome's JavaScript runtime, designed for creating fast and scalable network applications Its event-driven, non-blocking I/O model makes NodeJS lightweight and efficient, making it ideal for data-intensive, real-time applications across distributed devices.

NodeJS is an open-source, cross-platform runtime environment designed for building network and server-side applications It allows developers to write applications in JavaScript, which can operate on various operating systems, including OS X, Microsoft Windows, and Linux.

NodeJS also provides a library of many different JavaScript modules to simplify the development of web applications, thereby reducing the use of Node.js

• Asynchronous event-driven NodeJs allows handling multiple requests concurrently

• Powerful when handling real-time applications

• Respond to systems with huge traffic due to extremely fast response speed based on the core written in C++

• Powerful and constantly evolving library

• Compatible with all devices, multiple platforms

API, or Application Programming Interface, serves as a connection method between various libraries and applications, facilitating communication between software programs and operating systems Both Windows and Twitter offer APIs, each designed for specific functions and objectives Similar to how a keyboard enables user interaction with a computer, an API acts as a communication tool that bridges the gap between applications and their underlying systems.

• This is one of the new frameworks that will help you build HTTP services very simply and quickly

• Open source so you can use it by any client that supports XML, JSON

• It also has the ability to fully support HTTP components: URI, request/response headers, caching, versioning, content forma

• You can use hosts located in the application or on IIS

• An extremely suitable architecture for devices with limited bandwidth such as smartphones, tablets

• It usually has a data format of JSON, XML or any other data type

The REST principle and RESTful data structure are well-known concepts in the programming community, yet they are often misunderstood REST is not a technology but a methodology for designing APIs based on specific organizational principles These principles help programmers create a more efficient and comprehensive environment for processing API requests.

REST, or Representational State Transfer, is a set of guidelines and structures designed for data conversion While it is primarily utilized in web applications, REST can also be effectively applied to software data.

• In short, RESTful APIs are APIs that follow the REST structure

• Stateless (e.g., no server-side sessions)

• Use HTTP status codes when necessary

• Use URL endpoints with logical hierarchy

ReactJS is an open-source JavaScript library designed for the rapid and convenient development of user interface components Unlike traditional methods that embed JavaScript into HTML, such as AngularJS, ReactJS utilizes JSX to seamlessly integrate HTML within JavaScript This approach simplifies the process of incorporating HTML segments into JSX, enhancing the clarity and usability of components.

In React.js, while JavaScript is commonly utilized for website layout design, it can present structural complexities However, by employing JSX to embed HTML segments within JavaScript, the syntax becomes more intuitive and easier to comprehend This approach not only simplifies the coding process for developers but also enhances code optimization during compilation.

React's fundamental building blocks are known as components, which allow developers to write HTML using JavaScript for rendering To create a component, one can utilize the createClass method from the React object, serving as the initial step in working with this library Additionally, components can be nested within one another by using the return statement in the render method.

• In a program, there are many components, to simplify the management of those components, people use redux, redux is like a warehouse of components and when using a component, just call it

The Virtual DOM, while not created by React.js, is widely utilized and adheres to W3C standards for accessing HTML and XML code It is generated during program execution, serving as a storage space for components By leveraging the Virtual DOM, React.js enhances performance efficiency, allowing for swift updates whenever changes occur.

StarUML is a comprehensive modeling environment in graphical form and easy to use Uses StarUML provides:

- Presenting models with graphical symbols suitable for practical modeling methods such as entity and association models, relational models

- Automatically creating profiles describing objects on the model

- Automatically generating database generation code and processing functions from the built model

The role of StarUML in designing database models:

- Presenting models in graphical form

- Checking the validity of the designed model

- Generating logical data models or physical data models

A brief overview of entities, attributes, and relationships:

• Entities are concepts that refer to a class of objects with common characteristics that people want to manage information about For example, students, goods, supplies, etc

An individual, also known as an instance of an entity, refers to a specific object within that entity For instance, Nguyen Thuy represents an individual within the Student entity, while Candy serves as an instance of the Goods entity.

When describing an entity, individuals typically refer to its specific characteristics, known as attributes For instance, the Student entity includes attributes such as Student code, full name, date of birth, address, school, faculty, course, and class.

A relationship refers to the connection between two or more entities, characterized by three main types: one-to-one (1-1), many-to-many (n-n), and one-to-many (1-n).

• 1-1 relationship: Two entities A and B have a 1-1 relationship if one entity of type A corresponds to one entity of type B and vice versa

• 1-n relationship: Two entities A and B have a 1-n relationship if one entity of type A corresponds to many entities of type B and one entity of B corresponds to only one entity of type A

• n-n relationship: Two entities A and B have an n-n relationship if one entity of type A corresponds to many entities of type B and vice versa

MySQL is a relational database management system (RDBMS) that utilizes SQL (Transact-SQL) statements for data exchange between clients and the MySQL server An RDBMS encompasses various components, including databases, database engines, and applications designed to manage and organize data effectively.

MySQL is designed for large database environments, capable of handling terabytes of data and supporting thousands of simultaneous users It integrates seamlessly with various servers, including Microsoft Internet Information Server (IIS), E-Commerce Server, and Proxy Server, enhancing its versatility and performance.

ANALYSIS AND SYSTEM DESIGN

Identifying System Agents and Use Cases

The two main agent are Administrator and Customers:

The role involves overseeing the website's technical functions, addressing customer inquiries, and ensuring the system operates smoothly Key responsibilities encompass a range of tasks related to site maintenance and user support.

Effective website content management involves regularly updating product information, adjusting layouts, creating new content, and removing outdated materials to ensure a dynamic and engaging user experience.

• Handling Customer Requests: Accepting calls from customers about their feedback on products, their purchases, or problems they may have faced with their orders

• Managing Users: Management of user accounts, such as creating new ones, granting permissions, controlling which parts of the system a user has access to, and so on

• Manage Categories and Products: Add, edit, or delete product categories and individual products on the website Ensure the correct categorization and up-to-date product information

• Order Management: Customer orders, confirmation in their processing,and status changes in accordance with demand modifications

• Manage Comments: Ensure that all customer comments regarding products are accurate and associated only with appropriate usage of the site

• Revenue Statistics: Reviewing and analyzing revenue reports for the company's informed business decision-making

• Customer Reviews: Handling all customer reviews for a better service quality improvement plan

• View Statistics: Monitor the statistics for product views to understand the effectiveness of marketing strategies at attracting customer interest around products

The Customer engages with the website for the purposes of browsing and purchasing products The most important functions of the Customer include:

• Register: Create a new user account in the system All customers will register by entering the required details for access to features offered on the website

• Log in: Log in to the system using the registered account Customers can then update personal information, track orders, and so much more

• View Products: Find product information such as images, descriptions, and price information available at the website Customers may browse by category or look for a specific item

• Comment on Products: Write feedback or review products they have purchased or interested in This helps customers share experiences and act as a guide for others in their purchase decisions

• Order: Place an order to buy products, providing shipping addresses, payment methods, and order confirmation

Utilizing the website's search functionality, customers can effortlessly locate products by entering specific product names, categories, or other relevant terms, ensuring a streamlined shopping experience.

Register Login View Products Comment on Products Order

Login Manage Categories Manage Products Manage Orders Manage Comments Manage Website Manage Users Revenue Statistics Customer Reviews Product View Statistics

Use Case Diagrams

As per the usage scenarios of the primary actors, i will construct diagrams and descriptions regarding their relationship

• Description: customers can interact with main usecases by database system

• Description:administrator can interact with main usecases by database system

Figure 3 Order management use case

• Description: administrators can interact with the order management system, focusing on viewing the orders

"Extend" relationships indicate that extended functionality only occurs based on specific situations (when an order needs to be searched or deleted)

Figure 4 Catalog management use case

Administrators can effectively manage the catalog management system by engaging in key activities such as viewing, searching, and adding items The term "extend" refers to additional functionalities that are activated under specific circumstances, particularly when there is a need to search for, edit, or delete entries.

Figure 5 Product management use case

• Description: administrators can interact with the product management system, focusing on viewing, adding

"Extend" relationships indicate that extended functionality only occurs based on specific situations (when needs to be search, edit or deleted)

Figure 6 Member management use case

• Description: administrators can interact with the member management system, focusing on viewing, adding, permission

"Extend" relationships indicate that extended functionality only occurs based on specific situations (when needs to be search, edit, categorize or deleted)

Figure 7 Client-side management use case

• Description: customer can interact with the member management system, focusing on viewing, searching, ordering, commenting, contacting

"Extend" relationships indicate that extended functionality only occurs based on specific situations (when needs to be search details)

• Description: customer can interact with the order management system, focusing on ordering, add to cart

"Extend" relationships indicate that extended functionality only occurs based on specific situations (when needs to be search, purchase, submit, remove).

Detailed Use Case Description

• Brief description: This use case allows customers to log in to the system

• Flow of events: o Basic flow:

1 The use case begins when the customer invokes the login button First, the customer will be asked to fill in their email and password

2 The customer types in their email and password and clicks the

The "LOGIN" button initiates a verification process where the system checks the customer's email and password against the USERS table Upon successful validation, the system confirms the login and redirects the user to the home page, concluding the use case.

1 If at any point of execution of the use case making connection to the database is not possible, the error message is displayed by the system and this will end the use case

2 Step 2 and 3 of basic flow, specifically when user enters wrong or unused information or record is not found in USERS table It will show error message and request to re-enter it User can put Enter, resume or stop the action

• Brief description: This use case allows customers to view product information

• Flow of events: o Basic flow:

When a user clicks on a product, the SYSTEM retrieves relevant details such as the product list, image, description, price, quantity, and reviews from the PRODUCTS table, displaying this information on the SYSTEM GUI screen This completes the use case.

If the system fails to connect to the database at any point during the execution of the use case, it will display an error message and terminate the process.

• Brief description: This use case allows customers to search for products by keyword which is the product name

When a customer enters a product name in the search textbox and clicks the search icon, the system displays relevant products from the PRODUCTS table The displayed information includes the product name, image, and price, ensuring that users can easily find what they are looking for This process concludes once the results are shown.

1 In terms of full use case execution, if at any stage the system could not establish a connection to the Database, an error message will be displayed on the system

2 At step 1 in the basic flow, if the system could not find any product which match the entered text, the system will show the result : No product found The use case ends

• Brief description: This use case allows the user to change personal information

1 This use case begins after the user clicks the “Update information” button If successful, the system will go to the PERSONAL INFORMATION screen, extract the customer personal information: Full name, phone number, email, address from the USERS table and show it on screen

2 Update personal information: User types in what they would like to change, and they hit the "Update personal information" button System updates changed information into USERS table, and retrieves the personal information about the logged in user and displays on screen o Branching flow:

If the connection with the database is not possible at any time to execute the use case, the system will generate an error message The use case ends

• Postcondition: After the use case finishes successfully, the user's personal information will be updated in the USERS table

• Brief description: This use case allows customers to rate and comment on products

• Flow of events: o Basic flow:

1 This use case starts when the user clicks to view details of a product The system will retrieve the product information and display it on the

2 The user clicks on the comment section, enters the comment content and then clicks the “Submit” button The system will save the review to the PRODUCTCOMMENTS table The use case ends o Branching flow:

1 At any point during the use case, if the connection to the database cannot be established, the system will display an error message

2 At step 2 in the basic flow, if the user does not enter any content, the error message “Please enter a comment!” is displayed The use case ends

• Brief description: This use case allows customers to order products on the page

1 This use case starts when the user clicks on the add to cart button in the product details The system will get the product image, name, price, quantity information and display the message "Added to cart"

2 The user clicks on the "Cart" button on the screen, the system will switch to the product information screen in the cart

3 The user clicks on the "Payment" button on the screen, the system will switch to the payment screen

4 The user enters full information: gender, full name, phone number, address and then chooses the payment method, the system will switch to the order information confirmation screen

5 The user clicks the “Order” button, the system will create a new record in the ORDERS, ORDERDETAILS tables and update the PRODUCT table information, then display “Order successful”

Use case ends o Branching flow

1 At any time during the use case execution, if the connection to the database is not possible, the system will display an error message

2 At step 4 in the basic flow, if the inventory quantity is less than the order quantity, the error message “Invalid quantity” will be displayed and the use case ends

• Preconditions: Customers need to provide complete information to be able to place an order

• Postconditions: When the use case ends successfully, the information will be stored in the ORDERS, ORDERDETAILS tables, and the information will be updated in PRODUCT

• Brief description: This use case allows the administrator to log in to perform system maintenance functions

1 This use case starts when the user accesses the administration page

2 The administrator enters the correct email and password information and then presses the “LOGIN” button The system will perform a check in the USERS table If successful, it will move to the administration page screen o Branching flow:

1 At any point during the use case execution, if the connection to the database cannot be established, an error message will be displayed

2 At step 1 in the branching flow, if the administrator enters the wrong email and password information, an error message will be displayed If the login account does not have administrator rights, the system will move to the

• Preconditions: User Not Logged In

• Brief description: This use case allows the administrator to view and change the order status

1 This use case starts when the user clicks on the “Manage orders” button on the administration menu bar The system will retrieve the following information from the ORDERS and ORDERDETAILS tables: id, name of the person placing the order, email, address, product name, status, total amount, order date and display it on the screen

2 Update order status: a The administrator clicks on the update icon on a management bar The system will change the status of the order depending on the previous status

Use case ends o Branching flow:

1 At any point during the use case execution, if the connection to the database cannot be established, the system will display an error message and the use case ends

• Special requirements: It is necessary to control the permission to execute this use case to ensure safety and security

• Preconditions: The administrator needs to log in with administrative rights before executing the use case

• Postconditions: After the use case finishes successfully, save the information to the ORDERS table

• Brief description: This use case allows the administrator to view and update users

1 This use case starts when the user clicks on the “Manage users” button on the administration menu bar The system will retrieve the following information from the USERS table: Full name, phone number, email and display it on the screen

When the user clicks on the “Details” button, the system will display the user information interface including: Full name, email, address, phone number

Class Diagram Design Details

Desctrition: Below is a simple Class Diagram Design Details designed in sequential steps based on the description in chapter 2.3:

• Sequence diagram of adding members

• Add to cart sequence diagram

• Sequence diagram of adding products

• Sequence diagram for viewing product list

Figure 11 Sequence diagram of adding members

Figure 12 Add to cart sequence diagram

Figure 14 Sequence diagram of adding products

Figure 15 Sequence diagram for viewing product list

Database Design and Structure

No Attribute Data Type Description Note

1 id int(11) Mã danh mục

2 categoryName varchar(255) Tên danh mục

4 updatedAt datetime Ngày cập nhật

No Attribute Data Type Description Note

1 id int(11) Mã sản phẩm yêu thích

2 userId int(11) Mã người dùng

3 productId int(11) Mã sản phẩm

5 updatedAt datetime Ngày cập nhật

No Attribute Data Type Description Note

1 id int(11) Mã chi tiết đơn hàng

2 orderId int(11) Mã đơn hàng

3 productId int(11) Mã sản phẩm

4 size varchar(255) Kích thước giày

7 updatedAt datetime Ngày cập nhật

No Attribute Data Type Description Note

1 id int(11) Mã đơn hàng

2 userId int(11) Mã người dùng

3 status varchar(255) Trạng thái đơn hàng

4 totalPrice float Tổng hóa đơn

6 updatedAt datetime Ngày cập nhật

No Tên thuộc tính Kiểu dữ liệu Mô tả Note

1 id int(11) Mã bình luận

2 userId int(11) Mã người dùng

3 productId int(11) Mã sản phẩm

6 updatedAt datetime Ngày cập nhật

No Tên thuộc tính Kiểu dữ liệu Mô tả Note

1 id int(11) Mã sản phẩm

2 categoryId int(11) Mã danh mục

3 productName varchar(255) Tên sản phẩm

6 updatedAt datetime Ngày cập nhật

No Tên thuộc tính Kiểu dữ liệu Mô tả Note

1 id int(11) Mã người dùng

7 phoneNumber varchar(255) Số điện thoại

8 role tinyint(1) Vai trò người dùng

10 updatedAt datetime Ngày cập nhật

No Attribution Data Type Description Note

1 id int(11) Mã vận chuyển

2 userId int(11) Mã người dùng

3 productId int(11) Mã sản phẩm

5 size varchar(255) Kích cỡ giày

7 updatedAt datetime Ngày cập nhật

No Attribution Data Type Description Note

1 id int(11) Mã kích cỡ giày

2 productId int(11) Mã sản phẩm

15 updatedAt datetime Ngày cập nhật

No Attribution Data Type Description Note

1 id int(11) Mã kích cỡ giày

2 productId int(11) Mã sản phẩm

3 userId int(11) Mã người dùng

5 updatedAt datetime Ngày cập nhật

AI APPLICATION

AI Model using Colab and API

BERT (Bidirectional Encoder Representations from Transformers) is an advanced language model developed by Google in 2018, built on the Transformer architecture Its unique capability lies in understanding the context of words by analyzing both preceding and following words, which significantly enhances its performance in various natural language processing (NLP) tasks, including sentiment analysis.

BERT is based on the Transformer architecture, which is a powerful neural network architecture made from two major parts:

1 Encoder: The sequence of words is looked at throughout the entire text to understand the context

2 Self-Attention Mechanism: The capacity to calculate the relationship between every given word inside the sentence b Highlights of BERT

It reads the text from both left to right and vice-versa to increase the context significantly

BERT is pre-trained from huge data (Wikipedia, etc.) and then fine-tuned on specific issues

BERT hides some random words in the sentence while pre-training, predicting them from the context

Predicts wether two sentences are related to each other, thus learning the relationship between the two sentences

BERT understands context, as demonstrated in the sentence "I like to eat apples and drink apple juice," where it recognizes "apple" refers to the fruit rather than the brand.

This project utilizes BERT Multilingual (bert-base-multilingual-cased), which is extensively trained on a corpus of 104 languages, including Vietnamese By leveraging BERT Multilingual, the model can enhance its performance for Vietnamese by drawing on knowledge from other languages, particularly beneficial given the limited training data available for Vietnamese.

The BERT model is employed for sentiment analysis, categorizing input text into three distinct labels: positive, negative, and neutral This text classification task enables the model to effectively learn how to associate various inputs with their corresponding sentiment labels.

Fine-tuning involves adapting a pre-trained BERT model specifically for a designated task by training it on a Vietnamese dataset to enhance its performance in sentiment analysis This process updates the model's weights based on Vietnamese training data, aiming to align BERT's general knowledge with the unique characteristics of the Vietnamese language and sentiment interpretation.

The loss function's main objective is to evaluate the accuracy of the model's predictions during training In the context of sentiment analysis using BERT, which involves a classification task, Categorical Crossentropy is the most frequently utilized loss function.

Use the transformers library to load the pre-trained BERT model (BertForSequenceClassification) and fine-tune it on Vietnamese data

The main steps in building the model include:

1 Load the BERT model: model BertForSequenceClassification.from_pretrained('bert-base-multilingual-cased', num_labels=3)

2 Create the Dataset: The SentimentDataset class is created to process the training and testing data, including tokenizing text with a tokenizer and converting sentiment labels into numeric form

3 Train the model: The Trainer class from transformers is used to train and fine-tune the model

The model is represented by 14 sequential steps:

# 1 Read data from CSV file

# 3 Split data into X (features) and y (labels)

# 5 Split data into training and testing sets

# 6 Use BERT tokenizer to tokenize text

# 10 Create Trainer and train model

Read data from csv file, data used is taken from available external

Data preprocessing is an important step to prepare data for BERT model

My code performs the following preprocessing steps:

1.Clean up text: Remove special characters, unnecessary punctuation using regular expressions

(regex):re.sub(r'[^azAZàáảãạăắẳẵặâấẩẫậbcdéèẻẽẹêếềểễệfghíìỉĩịjklmnoóòỏ õọôốồổỗộơớờởỡợpqrstuúùủũụưứừửữựvwxyz]+', ' ', text)

2 Text normalization: Convert the entire text to lowercase: text.lower()

3 Stop word removal: Remove common words that do not have much semantic meaning (e.g "là", "và", "thì") using a list of Vietnamese stop words loaded from the file vietnamese-stopwords.txt

These preprocessing steps help remove noise in the data and focus on important features for sentiment analysis

The data is divided into three sets: training, testing, and validation

• Training set: Used to train the BERT model

• Testing set: Used to evaluate the performance of the model after training

• Validation set (optional): Used to fine-tune the model's hyperparameters during training

Use the train_test_split function from the sklearn library to split the data into a training set (80%) and a testing set (20%)

Step 4: Assign numeric representations (0, 1, 2) for the sentiment codes (pos, neg, neutral) using label_map & map

Step 5: Formulate train-test splits using train_test_split with an 80:20 ratio

Encode text with the BERT Tokenizer:

Step 6: BertTokenizer should be initialized from bert-base-multilingual- cased

Encode train and test text using tokenizer to achieve padding and truncation with a max_length of 128 tokens

Step 7: Create the SentimentDataset class that will take in encoded data and the corresponding labels

Create train_dataset and test_dataset from these encoded data

Step 8: Initialize the BertForSequenceClassification model from bert- base-multilingual-cased with 3 output labels, which includes pos, neg, and neutral Train the following Model:

Step 9: Define the training parameters such as number of epochs, batch size, learning rate among others in TrainingArguments

Step 10: Create a Trainer from model, train parameters and dataset

Train the model: trainer.train()

Figure 25 Create train_dataset and test_dataset

Step 11: Evaluate on test set using trainer.predict(), followed by retrieval of prediction results

Step 12: Print evaluation results for including accuracy and classification report Step 13: Make predictions for the new data by first encoding the text, then predicting the sentiment using the trained model and print the output prediction results

The trained model and tokenizer will be saved to the designated save_path

After training, the model and tokenizer are saved to the path '/content/drive/My Drive/saved_model' for future use To deploy the model on the web, an API is created to receive user input, process the data with the trained model, and return the prediction results.

Text → Tokenize → Create input as input_ids, attention_mask

Token through Transformer layers → Semantic Extraction → Results

Compare the predicted result with the actual label → Calculate Loss Backward Propagation:

Gradient is calculated through Loss → Update weights through Optimizer

Monitor Accuracy, Loss on training and validation sets to evaluate the model

Training with Hugging Face Trainer

Use TrainingArguments from transformers to configure training parameters, including:

• output_dir: Path to store training results

• num_train_epochs: Number of training epochs

• per_device_train_batch_size: Batch size for each device during training

• per_device_eval_batch_size: Batch size for each device during evaluation

• warmup_steps: Number of warmup steps

• weight_decay: Weight decay parameter

• logging_dir: Path to store logs

The Trainer class is used to train the model based on the configured parameters

After training, the model performance is evaluated on the test set using the following metrics:

• Accuracy: The ratio of correct predictions to total predictions

Use the accuracy_score and classification_report functions from sklearn to calculate and display this metric

• Broadly, Training Loss tends to decrease with steps as it shows that the model learns and progresses with time in training

• Indicating the initial course, Training Loss decreases quite rapidly followed by slowly decreasing and very small fluctuation

• This normal process is not showing in models learning more complex data features over the period after these steps

• The final Training Loss comes close to read about 0.1997, suggesting a very good convergence

• The overall achieved accuracy is 0.8888888888888888, approximately 88.89%

• That's quite achieved result, showing that the model is performing well enough in classifying the emotions

ValueError error with message: "Number of classes, 2, does not match size of target_names, 3 Try specifying the labels."

The ValueError arises because the classification_report identifies only 2 classes in y_pred, while the specified target_names indicate 3 classes: negative, neutral, and positive This discrepancy shows that the model is predicting only 2 classes, despite the dataset containing 3 distinct classes.

Imbalanced training data can hinder the ability of neural networks to effectively classify emotions into the three categories: negative, neutral, and positive This lack of proportionality in the training dataset may lead to inadequate learning and performance issues for the model.

• Incorrect code: Check the entire code, especially data processing and model definition, for the treatment of the three emotion classes

To ensure effective data verification, it is crucial to have a sufficient quantity of training data across all three emotional classes If any class lacks adequate data, consider employing various augmentation techniques or gathering additional data to enhance the dataset's balance and effectiveness.

• Code Check: Go through the code, emphasize especially the label handling and model definition, to cater for three emotion classes

• Debug: Go through debug tools to see the value of y_pred and validate why it has only 2 classes

The model demonstrates excellent performance, evidenced by a significant reduction in training loss and high accuracy However, the occurrence of a ValueError indicates an issue with the number of predicted classes To resolve this problem and further enhance the model's performance, a thorough review of both the data and the code is essential.

3.1.6 Benefits, Limitations and Future Work

High Accuracy: Very High Accuracy in Sentiment Analysis, as it understands the deep context

Adaptability: Adaptable for fine-tuning to new domains and languages

Simple Deployment: Hugging Face Transformers give very simple ways for deploying standard models

Computational Resource Requirement: High computational resources are required for training a BERT model and fine-tuning

Complicated: All BERT models are kind of complex and do not really make sense to a beginner

Difficult to Explain: Why a particular prediction was made by a model is difficult to explain

Performance improvement: Looking for ways to improve the performance of BERT for specific sentiment analysis tasks

Creating small models: The developing of smaller, more efficient versions of BERT, fit as small devices

Improved Methods for Explainability: Finding methods to make the decision of BERT models clearer.

Embedded AI

Embedded AI enables devices and systems to utilize Artificial Intelligence for real-time data processing and decision-making, eliminating the reliance on extensive external computational resources This section provides a comprehensive analysis of the different aspects of Embedded AI.

Embedded AI is defined as the integration of software and hardware technologies designed for resource-constrained environments Key technologies that comprise embedded AI include various advanced algorithms, machine learning models, and specialized hardware components.

Edge devices with AI accelerators (such as NVIDIA Jetson, Google Coral, or Apple Neural Engine)

Microcontrollers with minimal power and memory capabilities; these need to be small to run small AI models

TensorFlow.js: A library for machine learning which completely runs in the browser or Node.js environment, thus supporting easy deployment to devices

ONNX: Open Neural Network Exchange for interoperability between AI frameworks

Model Compression: Pruning and quantization techniques for reducing model size while preserving its accuracy

Real-Time Processing: Algorithms geared toward being low latency and high throughput

System of product recommendations, which personalizes experience for an end-user with relevant suggestions of products based on individual interests

Matrix Factorization involves breaking down a user-item matrix into two smaller matrices: userFactors and productFactors These matrices represent latent factors that are utilized by both users and products Each matrix contains columns corresponding to the number of latent factors, typically three in this case, with their values initialized using tf.randomNormal.

In a recommendation system, both users and items are characterized by vectors of latent factors The predicted rating a user assigns to an item is determined by calculating the dot product of the respective user and item vectors.

The model learns the latent factors by optimizing a loss function (usually MSE) to minimize the error between the predicted rating and the actual rating

Suppose i have the following user-item matrix (1: viewed, 0: not viewed):

Matrix Factorization will decompose this matrix into two smaller matrices (e.g with latentFactors = 2):

To predict user 1's rating for product 3, i would compute the dot product of the latent factor vectors of user 1 and product 3:

This predicted value indicates how interested user 1 is in product 3

The loss function measures the absolute output error between the training data matrix and the prediction matrix Specifically, it is expressed as the Mean Squared Error, which calculates the total of the squares of the errors.

The loss function computes the Mean Squared Error (MSE), representing the average squared difference between predicted values and actual data MSE is widely used as a loss function in regression tasks, including Matrix Factorization.

MSE is a differentiable loss function, allowing the use of gradient descent-based optimization algorithms

MSE penalizes large errors, encouraging the model to predict closer to the actual values

MSE is easy to understand and calculate

Adam, an optimization algorithm rooted in gradient descent, was employed to minimize the loss function for optimizing latent factors in deep learning The learning rate was set at 0.1, and the training loop was executed 100 times, with the loss function output displayed every 10 iterations.

The Adam algorithm (tf.train.adam) is employed in my code to optimize latent factors, utilizing its efficient gradient descent approach This widely recognized optimization method in deep learning is favored for its rapid convergence and effectiveness.

Adam calculates the gradient of the loss function with respect to the parameters

Adam uses this gradient to update the parameters, moving towards the side that reduces the loss function

Adam uses momentum to accelerate the convergence process

Adam adaptively adjusts the learning rate for each parameter

The learning rate is a crucial factor in optimization algorithms, as it dictates the size of the steps taken when updating parameters An excessively high learning rate may lead the algorithm to overlook the optimal solution, while a very low learning rate can result in slow convergence In this context, the learning rate has been established at 0.1.

The number of iterations in an optimization algorithm plays a crucial role in model training, as it dictates how many times the algorithm updates its parameters Insufficient iterations may prevent the model from adequately learning, while excessive iterations can result in overfitting In this case, the code specifies 100 iterations for optimal performance.

Get list of users and products

Create index mapping for users and products

After training a model, it can be easily deployed by saving and loading it for use in applications TensorFlow.js offers APIs that facilitate the saving and loading of models, accommodating various storage options including Local Storage, IndexedDB, and file systems.

To save the model, you have three options: use Local Storage to store it in the browser, save it to IndexedDB, which is a NoSQL database within the browser, or allow users to download the model as a file.

Load and use the model

To utilize a saved model, employ the function tf.loadLayersModel to load it effectively For making predictions, use the predict function, which accepts input data in tensor format and outputs the corresponding prediction results.

It is within the trainRecommendationModel that the training procedure for the suggested model is defined:

1.Data collecting: This is obtained from db.ProductView.findAll; user-product interaction data, which has information about the products viewed by users

The user-product matrix is constructed by transforming interaction data through the getUser ProductMatrix function This matrix defines the user-product relationship, where an entry of (i, j) equals 1 if user i views product j.

3 Initializing latent factors: The latent factors especially for users and products are initialized randomly using tf.randomNormal These bias features are referred to as the invisible features of users and products that enable the model to learn the correlation between the two

Improve AI models

• Handle missing data: Use Mean Imputation and KNN Imputation to fill in missing values in columns such as purchase history, age, and gender

• Outlier Removal: Apply Z-Score algorithm to detect and handle outliers in the dataset

• Data Transformation: o Use One-Hot Encoding for categorical columns such as gender, product type o Normalization of numeric values such as product price or quantity purchased

• Integrate data from tables such as: Purchase History, Customer

• Create a User-Item Interaction Matrix table as the basis for the recommendation algorithm

Hybrid Filtering: Combining Collaborative Filtering and Content-Based Filtering

• Apply Matrix Factorization (SVD) to reduce the user-product matrix, helping to detect potential relationships

• Build a User Similarity function based on Cosine Similarity to identify similar users

• Combine similarity scores with historical data to make suggestions

• Calculate similarity scores between products through attributes (price, category, description)

• Use TF-IDF Vectorizer algorithm to encode descriptive attributes and calculate Cosine Similarity between products

Deep Learning: Neural Collaborative Filtering (NCF)

• Create embedding layers representing users and products in vector space

To create a multi-layer neural network with fully connected layers, begin with an input layer that incorporates embeddings for both users and products Utilize hidden layers equipped with the ReLU activation function to effectively capture nonlinear features Finally, design the output layer to predict the similarity between users and products, enhancing recommendation accuracy.

• Loss function: Use Binary Cross-Entropy to optimize the model

• Improve accuracy: Apply Dropout technique (20%) to reduce overfitting

• Training parameters: o Epochs: 50 o Batch size: 256 o Optimizer: Adam with initial learning rate of 0.001

3.3.3 Increase Real-Time Behavior Analysis Capability

• Use Apache Kafka to process and transmit user behavior (such as clicks, product views) from client to backend

• Create a continuous data transmission pipeline to update suggestions in real time

• Apply Incremental Learning: Train only on new data instead of the entire data, reducing processing time

• Use TensorFlow.js to run trained models on the frontend, reducing latency when displaying suggestions

• Build RESTful API using NestJS:

• Endpoint /recommendations: Get userId and return a list of recommended products

• Endpoint /feedback: Capture feedback from users to improve the model

• Call API using Axios or Fetch API

• Integrate recommendation results directly into the user interface.

INSTALLATION AND DEPLOYMENT

Ngày đăng: 15/04/2025, 23:13

TRÍCH ĐOẠN

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

TÀI LIỆU LIÊN QUAN

🧩 Sản phẩm bạn có thể quan tâm

w