woensdag 26 mei 2021

03 CommonLit Readability Prize Kaggle

02 CommonLit Readability Prize Kaggle

 De eerste tests met een karakter gebaseerd NN zijn vrij dramatisch:


Poging 1 met dense NN



En poging 2

Self attention

Ik pas nu met name de learning rate aan naar 100 kleiner:


Dat ziet er iig al wat mooier uit. Tijd voor de eerste Kaggle submit! Het is een 'code competitie'. D.w.z. dat de volledige code via een ... moet worden aangeboden. Dat blijkt even lastig omdat niet alle libraries op Kaggle beschikbaar zijn. De selfattention kan ik wel toevoegen maar de cleantext module geeft wat problemen. Dan maar weer terug naar mijn eigen, eerder gemaakte opschoning subroutine.
Ik kom op uit op een score van 1.048 (topscore 26 mei 0.460). En daarmee op ongeveer de 1000e plaats. Hmmm. Maar goed. Het is het de eerste submit nog maar. Iig lijkt alles te werken. De voorspelde waarden liggen erg dicht bij elkaar:
[[-0.94634914]
 [-0.93451864]
 [-0.9363963 ]
 [-0.9408344 ]
 [-0.947149  ]
 [-0.94283646] 
[-0.947149 ]] 

Dit is iig wel dicht bij de gemiddelde waarde: -0.9593187699947071 






01 CommonLit Readability Prize Kaggle

Eindelijk weer een leuke Kaggle NLP competitie! De "CommonLit Readability Prize". Een wedstriijd om de complexiteit van teksten te waarderen. Uiteraard probeer ik dit niet op de klassieke wijze, met woord tokens maar wil ik meer info toevoegen door van de letters uit te gaan. De lengte van de woorden maar ook bijvoorbeeld de gebruikte tekens zullen gevoeldmatig mede de complexiteitswaarde bepalen.


Er zijn 2.834 teksten in de train-set (en maar 7 in de test-set) Dat is niet veel voor NLP. 

Eerst maar eens kijken hoe de teksten er uit zien. 

"All through dinner time, Mrs. Fayre was somewhat silent, her eyes resting on Dolly with a wistful, uncertain expression. She wanted to give the child the pleasure she craved, but she had hard work to bring herself to the point of overcoming her own objections.\nAt last, however, when the meal was nearly over, she smiled at her little daughter, and said, "All right, Dolly, you may go."\n"Oh, mother!" Dolly cried, overwhelmed with sudden delight. "Really?\nOh, I am so glad! Are you sure you\'re willing?"\n"I\'ve persuaded myself to be willing, against my will," returned Mrs. Fayre, whimsically. "I confess I just hate to have you go, but I can\'t bear to deprive you of the pleasure trip. And, as you say, it would also keep Dotty at home, and so, altogether, I think I shall have to give in."\n"Oh, you angel mother! You blessed lady! How good you are!" And Dolly flew around the table and gave her mother a hug that nearly suffocated her.'

Dit is en voorbeeld tekst. De bijbehoordende score is -0.3154 Wat wil dat nou zeggen?

Ok, eerst wat zijn de mogelijke scoringswaarden?

>>> np.max(y2)

1.7113898269999999

>>> np.min(y2)

-3.676267773

>>> np.average(y2)

-0.9593187699947071

>>> np.max(y2)-np.min(y2)

5.3876576

Laten we eens kijken hoe de eenvoudigste tekst er uit ziet

Deze tekst heeft de hoogste score (1.1711 ...)

'When you think of dinosaurs and where they lived, what do you picture? Do you see hot, steamy swamps, thick jungles, or sunny plains? Dinosaurs lived in those places, yes. But did you know that some dinosaurs lived in the cold and the darkness near the North and South Poles?\nThis surprised scientists, too. Paleontologists used to believe that dinosaurs lived only in the warmest parts of the world. They thought that dinosaurs could only have lived in places where turtles, crocodiles, and snakes live today. Later, these dinosaur scientists began finding bones in surprising places.\nOne of those surprising fossil beds is a place called Dinosaur Cove, Australia. One hundred million years ago, Australia was connected to Antarctica. Both continents were located near the South Pole. Today, paleontologists dig dinosaur fossils out of the ground. They think about what those ancient bones must mean.'

En deze de laagste (-3.6762 ...)

'The commutator is peculiar, consisting of only three segments of a copper ring, while in the simplest of other continuous current generators several times that number exist, and frequently 120! segments are to be found. These three segments are made so as to be removable in a moment for cleaning or replacement. They are mounted upon a metal support, and are surrounded on all sides by a free air space, and cannot, therefore, lose their insulated condition. This feature of air insulation is peculiar to this system, and is very important as a factor in the durability of the commutator. Besides this, the commutator is sustained by supports carried in flanges upon the shaft, which flanges, as an additional safeguard, are coated all over with hard rubber, one of the finest known insulators. It may be stated, without fear of contradiction, that no other commutator made is so thoroughly insulated and protected. The three commutator segments virtually constitute a single copper ring, mounted in free air, and cut into three equal pieces by slots across its face.'

Het lijkt er dus op dat de score hoger wordt naarmate de tekst minder complex wordt. Dit is de verdeling van de waarden:


Lijkt een aardige normaalverdeling maar wil wel zeggen dat de complexe teksten (55) en de meest eenvoudige (31) redelijk ondervertegenwoordigd zijn. ([ 55., 120., 280., 402., 490., 563., 458., 312., 123.,  31.]) Misschien zijn 5 bins beter:


 

Er is ook nog andere info beschikbaar zoals een url een licence en een standard error. Misschien later wat mee doen. 

Index(['id', 'url_legal', 'license', 'excerpt', 'target', 'standard_error'])

De teksten zijn gemiddels 972 karakters bestaande uit gemiddeld 172 woorden lang. (min 125 / max 205 woorden)