This project performs sentiment analysis on news articles using the Hugging Face Transformer AI model. It features user authentication, database management, and API endpoints to interact with the data.
- Features
- Installation
- Usage
- API Endpoints
- Database Schema
- Sentiment Analysis
- Tools and Languages
- Project Structure
- Contributing
- License
- User Authentication: Register and login users with hashed passwords.
- Database Management: Store and retrieve news articles and user profiles.
- Sentiment Analysis: Analyze sentiments of news articles using the Hugging Face
bertweet-base-sentiment-analysis
model.
-
Clone the repository:
git clone https://github.com/your-username/news-aggregator-sentiment-analysis.git cd news-aggregator-sentiment-analysis
-
Install dependencies:
npm install
-
Set up the database:
- Ensure you have MySQL installed and running.
- Create the necessary databases:
news_database
anduser_database
.
-
Configure the databases in your project: Update the database configuration in the respective files:
const sequelize = new Sequelize('database_name', 'username', 'password', { host: 'localhost', dialect: 'mysql' });
-
Run the application:
npm run dev
- Homepage:
GET /
- Welcome message. - User Management: Register and login users.
- Database Operations: View and interact with news articles stored in the database.
- Sentiment Analysis: View sentiment analysis results for news articles.
- List Users:
GET /users
- Create User:
POST /users
- Login User:
POST /login
- Generate API Key:
POST /generate-api-key
- View All News Articles:
GET /database
- View Specific Column:
GET /database/column?column=column_name
- Filter/Group by Category:
GET /database/column/category?category=category_name
- Look Up Headlines:
GET /database/headline?headline=some_headline
- Look Up Author:
GET /database/author?author=author_name
- Filter News by Date:
GET /database/date?date=YYYY-MM-DD
- View Sentiment Analysis Results:
GET /sentiment/headline?headline=some_headline
class newsData extends Model{}
newsData.init({
Category: { type: DataTypes.STRING, allowNull: false },
Headline: { type: DataTypes.STRING, allowNull: false },
Authors: { type: DataTypes.STRING }
});
class User extends Model{}
User.init({
userName: { type: DataTypes.STRING, allowNull: false, unique: true },
email: { type: DataTypes.STRING, allowNull: false },
password: { type: DataTypes.STRING, allowNull: false }
}, {
freezeTableName: true,
instanceMethods: {
generateHash(password) { return bcrypt.hash(password, bcrypt.genSaltSync(10)); },
validPassword(password) { return bcrypt.compare(password, this.password); }
}
});
The sentiment analysis feature in this project utilizes the Hugging Face bertweet-base-sentiment-analysis
model. This model is designed to analyze textual data and determine the sentiment conveyed in the text, categorizing it as positive, negative, or neutral.
- Data Preparation: The project reads news articles from a JSON dataset. Each article's text is extracted for sentiment analysis.
- Model Loading: The
bertweet-base-sentiment-analysis
model from Hugging Face is loaded using thetransformers
library in Python. This model is pre-trained for sentiment analysis tasks. - Sentiment Analysis: The text of each article is fed into the model, which returns a sentiment label (positive, negative, or neutral) along with a confidence score.
- Results Storage: The sentiment analysis results, including the headline, sentiment label, and confidence score, are stored in a JSON file and can be queried via API endpoints.
By integrating this AI model, the project can provide insights into the general sentiment of news articles, helping users understand the tone and emotional impact of the content they are reading.
- Programming Languages: JavaScript, Python
- Backend Framework: Node.js with Express
- Database: MySQL with Sequelize ORM
- AI Model: Hugging Face
bertweet-base-sentiment-analysis
- Libraries:
- Node.js: bcrypt for password hashing, fs for file system operations, jsonwebtoken for JWT management, nodemon for development
- Python: transformers for sentiment analysis, json for JSON parsing
- Development Tools: Git for version control
news_aggregator_api/
├── authController/
│ ├── authRouter.js
│ ├── file.txt
│ └── user.js
├── newsController/
│ ├── News_Category_Dataset_v3.json
│ ├── json_converter.py
│ └── news_database.js
│ ├── news_dataset.json
├── sentimentController/
│ ├── sentiment.js
│ ├── sentiment_analysis.py
│ └── sentiment_results.json
├── .gitignore
├── README.md
├── package-lock.json
├── package.json
└── server.js
Contributions are welcome! Please submit a pull request or open an issue to discuss potential changes.
This project is licensed under the MIT License. See the LICENSE file for details.