from belt_nlp.bert_classifier_with_pooling import BertClassifierWithPooling
from belt_nlp.tensor_utils import list_of_tensors_deep_equal

MODEL_PARAMS = {
    "num_labels": 2,
    "batch_size": 1,
    "learning_rate": 5e-5,
    "epochs": 1,
    "chunk_size": 510,
    "stride": 510,
    "minimal_chunk_length": 510,
    "pooling_strategy": "mean",
}
MODEL = BertClassifierWithPooling(**MODEL_PARAMS, device="cpu")

SHORT_REVIEW = """I saw this movie not knowing anything about it before hand. The plot was terrible with large gaps of information missing. The movie didn\'t have the "battle of wits" feel to me. The actors just spewed out mouthful\'s of nonsense, at times causing me to gnash my teeth in agony as they droned on and on. The plot was predictable except for the stomach sickening homo erotic scene at the end (I\'m not homophobic but made me physically sick to my stomach), even the ending was predictable. And you could tell the detective was Jude Law in a costume, everything from the fake accent, terrible dental work, costume shop facial hair, everything pointed to it being a disguise. The whole movie just felt like wasted time out of my life. This movie had the feel of a puppet show with Jude Law and Michael Caine as puppets and the house as the window to view the show, really boooring in my opinion."""  # noqa:E501
LONG_REVIEW = """Okay, so I'm not a big video game buff, but was the game House of the Dead really famous enough to make a movie from? Sure, they went as far as to actually put in quick video game clips throughout the movie, as though justifying any particular scene of violence, but there are dozens and dozens of games that look exactly the same, with the hand in the bottom on the screen, supposedly your own, holding whatever weapon and goo-ing all kinds of aliens or walking dead or snipers or whatever the case may be.<br /><br />It's an interesting premise in House of the Dead, with a lot of college kids (LOADED college kids, as it were, kids who are able to pay some fisherman something like $1,500 just for a ride after they miss their boat) trying to get out to this island for what is supposed to be the rave of the year. The first thing that comes to mind about House of the Dead after watching it is that it has become increasingly clear that modern horror movies have become nothing more than an exercise in coming up with creative ways to get a lot of scantily clad teenagers into exactly the same situations. At least in this case, the fact that they were on their way to a rave excuses the way the girls are dressed. They look badly out of place running around the woods in cute little halter-tops, but at least they THOUGHT they were dressed for the occasion.<br /><br />Clint Howard, tellingly the most interesting character in the film by far, delivers an absolutely awful performance, the greatness of which overshadows every other actor in the movie. I can't stand it when well-known actors change their accents in movies, it is so rarely effective, and Howard here shows that it is equally flat to have an well-known actor pretend that he's this hardened fisherman with a raspy voice from years of breathing salty air. He didn't even rasp well. It sounded like he was eating a cinnamon roll before shooting and accidentally inhaled some powdered sugar or something. Real tough there, Clint! I expected more from him, but then again, he did agree to a part in this mess.<br /><br />Once we get to the island, the movie temporarily turns into any one of the Friday the 13th movies that took place at Camp Crystal Lake. Lots of teenagers played by actors who were way too old for their parts getting naked and then killed. The nudity was impressive, I guess, but let's consider something for a minute. These kids pay almost two grand to get out to this island to go to the Rave Of The Year, find NO ONE, and say, well, who wants a beer! Even the guy who pulled that stack of hundreds out of his wallet to get them all over there didn't think anything of it that they found a full bar and not a single solitary person in sight. Here you have the input from director Uwe Boll - There's alcohol! They won't notice that the party they came for consists of no one but themselves!<br /><br />So not only do they start drinking, not minding the fact that the whole party seems to have vacated the island, but when one of the girls goes off into the dark woods to find out where everyone is (dragging one other girl and one of the guys reluctantly along), the guy and the girl who stay behind to get smashed decide that it would be a great idea to strip down for a quickie now that they're alone. It's like they expected to find the island empty, and now that they rest of the people that they came over with were gone for a little while, they would have some privacy since there's no one else around. Brilliant!<br /><br />Now for the things that everyone hated, judging by the reviews that I've read about the movie. Yes, intersplicing shots from the video game into the movie, mostly in order to show that, yes, the movie was being faithful to/directly copying the video game. Sure, it was a stupid idea. I can't imagine who thought up that little nugget, but worse than that is the Matrix-style bullet time scenes that were thrown in over and over and over and over. After the first time (at which point I found it pretentious and cheesy for a movie like this to have a shot like that as though it was something original) it is noticeable more for the technique of the shot itself rather than any dramatic meaning or creation of any kind of tension for the film.<br /><br />One of the things that makes a zombie film scary and gets you on the edge of your seat is to have them slowly but relentlessly coming after the living humans, who are much faster but getting tired, running out of places to run, and with a terrifying shortage of things with which to fight the zombies off with. The first two are done right in the movie, the kids are terrified and don't have a lot of places to run since they're on an island, but since they caught a ride over with a smuggler, they find themselves heavily armed. And I mean that very strongly. I mean, these people have everything from machine guns to hand grenades, which removes most of the tension of the impending walking dead.<br /><br />Then you have what I call the techno-slasher scene. Since the rave never happened, and I guess since Uwe Boll thought people were going to be disappointed at not hearing any techno music in the movie, there's one scene right in the middle where all the humans are fighting off the living dead, and amazingly enough it turns into something of a music video. There's techno music blasting as the shots are edited together faster and faster until it's nothing but a blur of gory shot, mostly only about 5 frames long (which is about 1/6 of a second) flashing across the screen in time with the speed techno music. Clever, I guess, but it has no place in a horror movie because it completely removes any sense of scariness or tension of even the gross-out effect because you can't see any one thing for long enough to react to it. You're just watching these shots fly across the screen and wondering what the hell the director was thinking when he decided that it would be a good idea to put something like this in the movie.<br /><br />I've seen a lot of people compare this movie to Resident Evil, mostly claiming that it copies the premise of it, and they're exactly right. I appreciate that at least here, as was not the case in Resident Evil, it wasn't some man-made virus that turned people into walking dead that were able to infect other people, changing them the way vampires turn others into vampires. 28 Days Later was also clearly an inspiration for this movie, it's just too bad that House of the Dead didn't do a single original thing, except for the somewhat moronic idea of putting in quick shots of the video game on which it is based, just in case you forget. I really think that this should have been a much better movie. While obviously I can't say that I know much about the game it's based on, just the title and the movie poster deserve a much better movie, but unfortunately I think that's more often the case than not with horror movies. It's really kind of sad when a movie comes out that is so obviously advertised as a no-holds-barred horror film, and the scariest thing in the entire movie is the closing shot, which suggests the possibility of a sequel."""  # noqa:E501


def test_tokenize():
    tokens_short = MODEL._tokenize([SHORT_REVIEW])
    assert list(tokens_short["input_ids"][0].shape) == [1, 512]
    assert list(tokens_short["attention_mask"][0].shape) == [1, 512]

    tokens_long = MODEL._tokenize([LONG_REVIEW])
    expected_number_of_chunks = 3
    assert list(tokens_long["input_ids"][0].shape) == [expected_number_of_chunks, 512]
    assert list(tokens_long["attention_mask"][0].shape) == [expected_number_of_chunks, 512]

    tokens_two_texts_in_batch = MODEL._tokenize([SHORT_REVIEW, LONG_REVIEW])
    expected_input_ids = tokens_short["input_ids"] + tokens_long["input_ids"]
    expected_attention_mask = tokens_short["attention_mask"] + tokens_long["attention_mask"]
    assert list_of_tensors_deep_equal(tokens_two_texts_in_batch["input_ids"], expected_input_ids)
    assert list_of_tensors_deep_equal(tokens_two_texts_in_batch["attention_mask"], expected_attention_mask)
