| Attribute | Value |
|---|---|
| Developed by | Petercusin (Guisheng Pan) |
| Model Architecture | fasttext |
| Number of words | 267,799 |
| Number of labels | 42 |
| Labels | ['Arts', 'Arts & Culture', 'Black voices', 'Business', 'College', 'Comedy', 'Crime', 'Culture & Arts', 'Divorce', 'Education', 'Entertainment', 'Environment', 'Fifty', 'Food & Drink', 'Good news', 'Green', 'Healthy living', 'Home & Living', 'Impact', 'Latino voices', 'Media', 'Money', 'Parenting', 'Parents', 'Politics', 'Queer voices', 'Religion', 'Science', 'Sports', 'Style', 'Style & Beauty', 'Taste', 'Tech', 'The worldpost', 'Travel', 'U.S. news', 'Weddings', 'Weird news', 'Wellness', 'Women', 'World news', 'Worldpost'] |
| Words/sec/thread | 497,437 |
| Learning rate | 0.000000 |
| Average loss | 0.550502 |
| Model saved to | PGS_news_classifier.bin (890M) |
| Precision@1 | 0.7414219768714605 |
| Recall@1 | 0.7414219768714605 |
| Number of examples | 42,026 (test data) |
1# -*- coding: utf-8 -*-
2"""
3Created on Sun Apr 20 20:24:58 2025
4
5@author: Petercusin
6"""
7
8import fasttext
9# pip install pgsfile
10# https://pypi.org/project/PgsFile/
11from PgsFile import predict_category
12
13# Load the trained model
14model_path = "PGS_news_classifier.bin"
15model = fasttext.load_model(model_path)
16
17# New titles or texts to classify
18new_titles = [
19 "Stock markets reach all-time high amid economic recovery",
20 "Scientists discover new species in Amazon rainforest",
21 "Congress passes new bill on healthcare reforms",
22 "The stairway to love: Chongqing's real-life fairy tale",
23 "African delegation take in Shanghai sights on Huangpu cruise",
24 "China expected to achieve higher grain output in 2025: report",
25 "China continued its dominance at the 2025 World Aquatics Diving World Cup in Guadalajara, sweeping all four gold medals on the third day of competitions on Saturday, along with one silver.",
26 "A 'DeepSeek moment for AI agents' as China launches Manus",
27 "Developed by Monica.im, Manus achieved top scores on the GAIA (General AI Assistant) benchmark, exceeding those of OpenAI's GPT (generative pre-trained transformer) tools. GAIA is a real-world benchmark for general AI assistants.",
28 "This week and without warning, a horrid video popped up on my phone. A puppy had its mouth and paws bound with tape, and was hanging in a plastic bag by the motorway. I immediately flicked past, but the image stayed with me. This was something I didn’t want to see, yet there it was at 11am on a Tuesday."
29]
30
31try:
32 # Process new titles
33 for title in new_titles:
34 label, score = predict_category(model, title)
35 print(f"Title/Text: {title}")
36 print(f"Predicted category: <{label}> (confidence: {score:.2f})")
37 print("*" * 50) # Add a separator line for better readability
38finally:
39 # Explicitly delete the model to free up memory
40 del model1Title/Text: Stock markets reach all-time high amid economic recovery
2Predicted category: <BUSINESS> (confidence: 1.00)
3**************************************************
4Title/Text: Scientists discover new species in Amazon rainforest
5Predicted category: <SCIENCE> (confidence: 0.99)
6**************************************************
7Title/Text: Congress passes new bill on healthcare reforms
8Predicted category: <POLITICS> (confidence: 1.00)
9**************************************************
10Title/Text: The stairway to love: Chongqing's real-life fairy tale
11Predicted category: <ENTERTAINMENT> (confidence: 0.04)
12**************************************************
13Title/Text: African delegation take in Shanghai sights on Huangpu cruise
14Predicted category: <TRAVEL> (confidence: 0.89)
15**************************************************
16Title/Text: China expected to achieve higher grain output in 2025: report
17Predicted category: <WORLDPOST> (confidence: 0.01)
18**************************************************
19Title/Text: China continued its dominance at the 2025 World Aquatics Diving World Cup in Guadalajara, sweeping all four gold medals on the third day of competitions on Saturday, along with one silver.
20Predicted category: <SPORTS> (confidence: 0.19)
21**************************************************
22Title/Text: A 'DeepSeek moment for AI agents' as China launches Manus
23Predicted category: <TECH> (confidence: 0.99)
24**************************************************
25Title/Text: Developed by Monica.im, Manus achieved top scores on the GAIA (General AI Assistant) benchmark, exceeding those of OpenAI's GPT (generative pre-trained transformer) tools. GAIA is a real-world benchmark for general AI assistants.
26Predicted category: <TECH> (confidence: 0.94)
27**************************************************
28Title/Text: This week and without warning, a horrid video popped up on my phone. A puppy had its mouth and paws bound with tape, and was hanging in a plastic bag by the motorway. I immediately flicked past, but the image stayed with me. This was something I didn’t want to see, yet there it was at 11am on a Tuesday.
29Predicted category: <ENTERTAINMENT> (confidence: 0.04)
30**************************************************