Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
language:
|
| 4 |
+
- en
|
| 5 |
+
---
|
| 6 |
+
|
| 7 |
+
We trained a language model to **automatically score the IELTS essays** by using massive the training dataset by human raters.
|
| 8 |
+
|
| 9 |
+
The impressive result in the test dataset is as follows: **Accuracy = 0.82, F1 Score = 0.81**.
|
| 10 |
+
|
| 11 |
+
The following is the code to implement the model for scoring new IELTS essays.
|
| 12 |
+
|
| 13 |
+
In the following example, an essay is taken from the test dataset with the overall score 8.
|
| 14 |
+
|
| 15 |
+
```
|
| 16 |
+
# Import necessary packages
|
| 17 |
+
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
| 18 |
+
import torch
|
| 19 |
+
import numpy as np
|
| 20 |
+
|
| 21 |
+
# Load the pre-trained model and tokenizer
|
| 22 |
+
model_path = "./ielts_scoring_model"
|
| 23 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_path)
|
| 24 |
+
tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased", use_fast=True)
|
| 25 |
+
|
| 26 |
+
# Example text to be evaluated, the essay with the score by human rater (= 8.5) in the test dataset.
|
| 27 |
+
|
| 28 |
+
new_text = (
|
| 29 |
+
"It is important for all towns and cities to have large public spaces such as squares and parks. "
|
| 30 |
+
"Do you agree or disagree with this statement? It is crucial for all metropolitan cities and towns to "
|
| 31 |
+
"have some recreational facilities like parks and squares because of their numerous benefits. A number of "
|
| 32 |
+
"arguments surround my opinion, and I will discuss it in upcoming paragraphs. To commence with, the first "
|
| 33 |
+
"and the foremost merit is that it is beneficial for the health of people because in morning time they can "
|
| 34 |
+
"go for walking as well as in the evenings, also older people can spend their free time with their loved ones, "
|
| 35 |
+
"and they can discuss about their daily happenings. In addition, young people do lot of exercise in parks and "
|
| 36 |
+
"gardens to keep their health fit and healthy, otherwise if there is no park they glue with electronic gadgets "
|
| 37 |
+
"like mobile phones and computers and many more. Furthermore, little children get best place to play, they play "
|
| 38 |
+
"with their friends in parks if any garden or square is not available for kids then they use roads and streets "
|
| 39 |
+
"for playing it can lead to serious incidents. Moreover, parks have some educational value too, in schools, "
|
| 40 |
+
"students learn about environment protection in their studies and teachers can take their pupils to parks because "
|
| 41 |
+
"students can see those pictures so lively which they see in their school books and they know about importance "
|
| 42 |
+
"and protection of trees and flowers. In recapitulate, parks holds immense importance regarding education, health "
|
| 43 |
+
"for people of every society, so government should build parks in every city and town."
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
# Encode the text using the same tokenizer used during training
|
| 47 |
+
encoded_input = tokenizer(new_text, return_tensors='pt', padding=True, truncation=True, max_length=512)
|
| 48 |
+
|
| 49 |
+
# Set the model to evaluation mode
|
| 50 |
+
model.eval()
|
| 51 |
+
|
| 52 |
+
# Perform the prediction
|
| 53 |
+
with torch.no_grad():
|
| 54 |
+
outputs = model(**encoded_input)
|
| 55 |
+
|
| 56 |
+
# Get the predictions (the output here depends on whether you are doing regression or classification)
|
| 57 |
+
predictions = outputs.logits.squeeze()
|
| 58 |
+
|
| 59 |
+
# Assuming the model is a regression model and outputs raw scores
|
| 60 |
+
predicted_scores = predictions.numpy() # Convert to numpy array if necessary
|
| 61 |
+
|
| 62 |
+
# Normalize the scores
|
| 63 |
+
normalized_scores = (predicted_scores / predicted_scores.max()) * 9 # Scale to 9
|
| 64 |
+
|
| 65 |
+
# Round the scores to the nearest 0.5 increment
|
| 66 |
+
rounded_scores = np.round(normalized_scores * 2) / 2
|
| 67 |
+
|
| 68 |
+
item_names = ["Task Achievement", "Coherence and Cohesion", "Vocabulary", "Grammar", "Overall"]
|
| 69 |
+
|
| 70 |
+
# Print the predicted scores
|
| 71 |
+
for item, score in zip(item_names, rounded_scores):
|
| 72 |
+
print(f"{item}: {score:.1f}")
|
| 73 |
+
|
| 74 |
+
##the output:
|
| 75 |
+
#Task Achievement: 9.0
|
| 76 |
+
#Coherence and Cohesion: 7.5
|
| 77 |
+
#Vocabulary: 8.0
|
| 78 |
+
#Grammar: 7.5
|
| 79 |
+
#Overall: 8.5
|
| 80 |
+
```
|