This project is an executable prototype for scoring the stylistic level of Persian sentences. The user enters a Persian sentence in the graphical interface, and the system estimates its stylistic level, or degree of literary expression, on a scale from 1 to 10.
In this project, “literariness” is defined operationally. Instead of making a broad judgment about the artistic value of a text, the system focuses on observable linguistic signals, such as distance from everyday speech, level of formality, elevated wording, imagery, emotional or literary vocabulary, and classical or poetic markers.
In Persian, the same meaning can be expressed with different tones and stylistic levels. For example, the idea of not feeling well emotionally can be written in several ways:
Colloquial: امروز اصلا سرحال نیستم.
Standard: امروز حال خوبی ندارم.
Formal: امروز از نظر روحی در وضعیت مناسبی نیستم.
Literary: امروز سایهای از دلتنگی با من مانده است.
The goal of the project is to turn these stylistic differences into a numerical and analyzable output. To do this, the system uses two types of information: explainable linguistic features and sentence embeddings generated by ParsBERT. The linguistic features make part of the scoring logic interpretable, while ParsBERT provides contextual information about the sentence.
In the current version, the project is used through a graphical interface. The user enters a sentence, the Python service processes it, the saved model runs the prediction, and the result is displayed in the same interface.
The model output is a number between 1 and 10. The table below shows the approximate meaning of each score and helps interpret the model output.
| Score | Interpretation |
|---|---|
| 1 | Fully colloquial, everyday, chat-like, broken, and loosely structured |
| 2 | Colloquial but slightly more organized, simple, and close to ordinary speech |
| 3 | Simple standard Persian, understandable, with no serious literary markers |
| 4 | Standard and explanatory, more organized than speech, but still non-literary |
| 5 | Simple formal or administrative language, with formal vocabulary and no literary imagery |
| 6 | Academic or analytical, more conceptual and complex, but not poetic |
| 7 | Mildly literary, emotional, with simple imagery and a more elevated tone |
| 8 | Richly literary, with clear metaphor and imagery, close to poetic prose |
| 9 | Highly literary and symbolic, with elevated structure and dense imagery |
| 10 | Very elevated or classical-like prose, with heavy literary vocabulary and structures |
The prototype dataset is located at:
data/persian_literary_5000.json
This file contains 5,000 Persian sentences. Each record includes an ID, the sentence text, the stylistic score, and the data split:
id, sentence, score, split
The current dataset is an AI-generated synthetic corpus. The sentences were generated with the help of a generative AI system based on the operational scoring scale used in this project. The stylistic scores were also assigned during the same data-generation process.
Therefore, the current dataset should be understood as a prototype dataset for technical feasibility testing, not as a human-annotated benchmark for Persian stylistic analysis. It is useful for testing the full pipeline, including preprocessing, linguistic feature extraction, ParsBERT embedding generation, model training, and prediction. However, the current results should not be interpreted as final evidence of generalization to real Persian texts.
Future versions of the project should include real Persian sentences collected from diverse sources and scored by multiple human annotators.
The saved model uses the following data split:
| Split | Number of Samples |
|---|---|
| Train | 4,000 |
| Validation | 500 |
| Test | 500 |
The base language model is HooshvareLab/bert-fa-base-uncased. In this project, ParsBERT is not fine-tuned; it is used only to generate sentence embeddings. These embeddings are combined with linguistic features, and a lightweight Ridge Regression model predicts the final score.
The trained model is saved at:
models/literary_parsbert_light.joblib
This file contains the saved model, the feature scaler, the base model name, the feature keys, and training-related information.
Explainable linguistic features are extracted in:
scripts/features.py
These features include:
- sentence length, word count, character count, and average word length;
- colloquial words and informal forms;
- formal and administrative vocabulary;
- academic and analytical vocabulary;
- literary, emotional, and imagery-based vocabulary;
- classical or archaic-looking vocabulary;
- figurative and literary expressions;
- punctuation markers such as commas, semicolons, question marks, and exclamation marks.
These features help make the model output more interpretable. For example, a sentence with emotional vocabulary, figurative expressions, or a more elevated structure will usually move toward a higher stylistic score.
The current version of the project is centered around the graphical interface. The main files are:
index.php main graphical interface
scripts/predict_server.py local service that receives requests from the GUI
scripts/predict_core.py sentence preparation and prediction logic
scripts/parsbert_utils.py ParsBERT loading and sentence embedding generation
scripts/features.py explainable linguistic feature extraction
models/literary_parsbert_light.joblib
trained model
scripts/train_light_parsbert.py model retraining script, if needed
data/persian_literary_5000.json 5,000-sentence prototype corpus
In normal use, the user only interacts with index.php. The graphical interface receives the sentence and sends it to the local Python service. The Python service runs the saved model and returns the result to the interface.
The internal process of the GUI version works as follows:
- The user enters a Persian sentence in the graphical interface.
index.phpsends the text to the local Python service.predict_server.pyreceives the request and passes it to the prediction logic.predict_core.pyprepares the sentence, extracts linguistic features, and generates the ParsBERT embedding.- The saved model in
literary_parsbert_light.joblibruns the prediction. - The final score, stylistic label, and short explanation are returned to the graphical interface.
To run the GUI version, execute the following command in the project directory:
php -S localhost:8000Then open this address in the browser:
http://localhost:8000/index.php
The main page of the project will be displayed. The user enters a Persian sentence, and the analysis result appears on the same page.
The results stored in the current model are consistent with the research report:
| Split | MAE | RMSE | Rounded Accuracy | Within-1 Accuracy |
|---|---|---|---|---|
| Validation | 0.115 | 0.156 | 0.998 | 1.000 |
| Test | 0.111 | 0.157 | 0.996 | 1.000 |
These numbers show that the model has reconstructed the patterns in the prototype corpus with low error. Since the current dataset is AI-generated and the labels were assigned during the same data-generation process, the high accuracy should be interpreted with caution. The reported results are best understood as evidence that the proposed pipeline is technically feasible and internally consistent on the prototype corpus. They should not be treated as final proof that the model can accurately score the stylistic level of real Persian sentences.
Several important points should be addressed in future work:
- The current dataset is AI-generated and should be replaced or extended with real Persian sentences from diverse sources.
- The stylistic labels should be strengthened through multiple human annotators.
- Annotator agreement can be measured using metrics such as weighted kappa or Krippendorff’s alpha.
- The model should be compared with simpler baselines, such as a feature-only model, a ParsBERT-only model, and a model that always predicts the mean score.
- Error analysis is needed to identify the types of sentences the model misjudges.
- Evaluation on real and diverse Persian texts, such as news, social media posts, administrative letters, fictional prose, and literary texts, can strengthen the validity of the research.
This project is an executable prototype for scoring the stylistic level of Persian sentences. Its main idea is to combine two sources of information: explainable linguistic features and sentence embeddings generated by ParsBERT. The output is a numerical score from 1 to 10 that represents the sentence’s position on a spectrum from colloquial to literary Persian.
The current version is usable through a graphical interface and is designed for research presentation, sample analysis, and demonstrating the practical usability of the model. Because the current dataset is AI-generated, the project should be viewed as an executable research prototype and technical feasibility study, not as a final validated benchmark for Persian stylistic scoring.