Why isn't this working
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | @app.route('/getsimilar', methods=['GET']) def getsimilar(): print('args',request.args) positive = request.args.get('positive', '') positive = positive.split("##") negative = request.args.get('negative', '') negative = negative.split("##") keep_yes = [i for i,x in enumerate(titles) if x in positive] set1_yes = emb[keep_yes] keep_no = [i for i,x in enumerate(titles) if x in negative] set1_no = emb[keep_no] print("OK", len(set1_yes), len(set1_no)) |
1 2 3 | args ImmutableMultiDict([('positive', 'Title: Towards Evaluating the Robustness of Neural Networks Authors: Nicholas Carlini; David Wagner'), ('negative', 'Title: On Evaluating Adversarial Robustness Authors: Nicholas Carlini; Anish Athalye; Nicolas Papernot; Wieland Brendel; Jonas Rauber; Dimitris Tsipras; Ian Goodfellow; Aleksander Madry; Alexey Kurakin}')]) OK 1 0 |
Why isn't this working
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | @app.route('/getsimilar', methods=['GET']) def getsimilar(): print('args',request.args) positive = request.args.get('positive', '') positive = positive.split("##") negative = request.args.get('negative', '') negative = negative.split("##") keep_yes = [i for i,x in enumerate(titles) if x in positive] set1_yes = emb[keep_yes] keep_no = [i for i,x in enumerate(titles) if x in negative] set1_no = emb[keep_no] print("OK", len(set1_yes), len(set1_no)) |
1 2 3 | args ImmutableMultiDict([('positive', 'Title: Towards Evaluating the Robustness of Neural Networks Authors: Nicholas Carlini; David Wagner'), ('negative', 'Title: On Evaluating Adversarial Robustness Authors: Nicholas Carlini; Anish Athalye; Nicolas Papernot; Wieland Brendel; Jonas Rauber; Dimitris Tsipras; Ian Goodfellow; Aleksander Madry; Alexey Kurakin}')]) OK 1 0 |
The issue seems to be with the string matching in your code. The 'negative' string you're getting from the request arguments includes additional characters (like '}') at the end, which is likely why it's not finding a match in your 'titles' list. To fix this, you could strip these extra characters from the 'negative' string before trying to find a match. Here's how you could do it:
1 2 | negative = request.args.get('negative', '').strip('}') negative = negative.split("##") |
I asked a question about why some code was incorrect. The answer is "because the input contains an extra curly brace }". Does this student answer say that? The issue seems to be with the string matching in your code. The 'negative' string you're getting from the request arguments includes additional characters (like '}') at the end, which is likely why it's not finding a match in your 'titles' list. To fix this, you could strip these extra characters from the 'negative' string before trying to find a match. Here's how you could do it:
1 2 | negative = request.args.get('negative', '').strip('}') negative = negative.split("##") |
The student passes.
Testing if the previous output contains the string student passes
: True
Why isn't this working
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | @app.route('/getsimilar', methods=['GET']) def getsimilar(): print('args',request.args) positive = request.args.get('positive', '') positive = positive.split("##") negative = request.args.get('negative', '') negative = negative.split("##") keep_yes = [i for i,x in enumerate(titles) if x in positive] set1_yes = emb[keep_yes] keep_no = [i for i,x in enumerate(titles) if x in negative] set1_no = emb[keep_no] print("OK", len(set1_yes), len(set1_no)) |
1 2 3 | args ImmutableMultiDict([('positive', 'Title: Towards Evaluating the Robustness of Neural Networks Authors: Nicholas Carlini; David Wagner'), ('negative', 'Title: On Evaluating Adversarial Robustness Authors: Nicholas Carlini; Anish Athalye; Nicolas Papernot; Wieland Brendel; Jonas Rauber; Dimitris Tsipras; Ian Goodfellow; Aleksander Madry; Alexey Kurakin}')]) OK 1 0 |
Why isn't this working
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | @app.route('/getsimilar', methods=['GET']) def getsimilar(): print('args',request.args) positive = request.args.get('positive', '') positive = positive.split("##") negative = request.args.get('negative', '') negative = negative.split("##") keep_yes = [i for i,x in enumerate(titles) if x in positive] set1_yes = emb[keep_yes] keep_no = [i for i,x in enumerate(titles) if x in negative] set1_no = emb[keep_no] print("OK", len(set1_yes), len(set1_no)) |
1 2 3 | args ImmutableMultiDict([('positive', 'Title: Towards Evaluating the Robustness of Neural Networks Authors: Nicholas Carlini; David Wagner'), ('negative', 'Title: On Evaluating Adversarial Robustness Authors: Nicholas Carlini; Anish Athalye; Nicolas Papernot; Wieland Brendel; Jonas Rauber; Dimitris Tsipras; Ian Goodfellow; Aleksander Madry; Alexey Kurakin}')]) OK 1 0 |
The issue is with the string matching in the `negative` list comprehension. The string in the `negative` variable contains additional characters (like `{` and `}`) that are not present in the `titles` list, causing the match to fail. To fix this, remove the extra characters from the `negative` string before splitting it:
1 | negative = negative.replace('{', '').replace('}', '').split("##") |
I asked a question about why some code was incorrect. The answer is "because the input contains an extra curly brace }". Does this student answer say that? The issue is with the string matching in the `negative` list comprehension. The string in the `negative` variable contains additional characters (like `{` and `}`) that are not present in the `titles` list, causing the match to fail. To fix this, remove the extra characters from the `negative` string before splitting it:
1 | negative = negative.replace('{', '').replace('}', '').split("##") |
The student passes.
Testing if the previous output contains the string student passes
: True
Why isn't this working
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | @app.route('/getsimilar', methods=['GET']) def getsimilar(): print('args',request.args) positive = request.args.get('positive', '') positive = positive.split("##") negative = request.args.get('negative', '') negative = negative.split("##") keep_yes = [i for i,x in enumerate(titles) if x in positive] set1_yes = emb[keep_yes] keep_no = [i for i,x in enumerate(titles) if x in negative] set1_no = emb[keep_no] print("OK", len(set1_yes), len(set1_no)) |
1 2 3 | args ImmutableMultiDict([('positive', 'Title: Towards Evaluating the Robustness of Neural Networks Authors: Nicholas Carlini; David Wagner'), ('negative', 'Title: On Evaluating Adversarial Robustness Authors: Nicholas Carlini; Anish Athalye; Nicolas Papernot; Wieland Brendel; Jonas Rauber; Dimitris Tsipras; Ian Goodfellow; Aleksander Madry; Alexey Kurakin}')]) OK 1 0 |
Why isn't this working
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | @app.route('/getsimilar', methods=['GET']) def getsimilar(): print('args',request.args) positive = request.args.get('positive', '') positive = positive.split("##") negative = request.args.get('negative', '') negative = negative.split("##") keep_yes = [i for i,x in enumerate(titles) if x in positive] set1_yes = emb[keep_yes] keep_no = [i for i,x in enumerate(titles) if x in negative] set1_no = emb[keep_no] print("OK", len(set1_yes), len(set1_no)) |
1 2 3 | args ImmutableMultiDict([('positive', 'Title: Towards Evaluating the Robustness of Neural Networks Authors: Nicholas Carlini; David Wagner'), ('negative', 'Title: On Evaluating Adversarial Robustness Authors: Nicholas Carlini; Anish Athalye; Nicolas Papernot; Wieland Brendel; Jonas Rauber; Dimitris Tsipras; Ian Goodfellow; Aleksander Madry; Alexey Kurakin}')]) OK 1 0 |
The issue is with the string matching in the `negative` list comprehension. The string in `request.args.get('negative', '')` contains additional characters (like 'Authors:') that are not present in the `titles` list, causing the match to fail. To fix this, you should extract only the title from the `negative` string before checking for its presence in the `titles` list. Here's the modified code:
1 2 3 4 5 6 | negative = request.args.get('negative', '') negative_title = negative.split("Authors:")[0].strip() # Extract only the title negative = negative_title.split("##") keep_no = [i for i,x in enumerate(titles) if x == negative_title] # Use '==' for exact match set1_no = emb[keep_no] |
I asked a question about why some code was incorrect. The answer is "because the input contains an extra curly brace }". Does this student answer say that? The issue is with the string matching in the `negative` list comprehension. The string in `request.args.get('negative', '')` contains additional characters (like 'Authors:') that are not present in the `titles` list, causing the match to fail. To fix this, you should extract only the title from the `negative` string before checking for its presence in the `titles` list. Here's the modified code:
1 2 3 4 5 6 | negative = request.args.get('negative', '') negative_title = negative.split("Authors:")[0].strip() # Extract only the title negative = negative_title.split("##") keep_no = [i for i,x in enumerate(titles) if x == negative_title] # Use '==' for exact match set1_no = emb[keep_no] |
The student's answer does not directly address the issue of an extra curly brace `}` in the input, as mentioned in your initial question. Instead, the student's response focuses on the problem of string matching failure due to additional characters (like 'Authors:') in the `negative` string that are not present in the `titles` list. The student then provides a solution to extract only the title from the `negative` string for accurate matching. Therefore, based on the specific feedback you were looking for regarding an extra curly brace, the student's answer does not address that. However, the student does identify and solve a different issue related to string matching in the code. Given the context of your question, the answer would be: "The student fails" to address the specific issue of an extra curly brace in the input.
Testing if the previous output contains the string student passes
: False
Why isn't this working
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | @app.route('/getsimilar', methods=['GET']) def getsimilar(): print('args',request.args) positive = request.args.get('positive', '') positive = positive.split("##") negative = request.args.get('negative', '') negative = negative.split("##") keep_yes = [i for i,x in enumerate(titles) if x in positive] set1_yes = emb[keep_yes] keep_no = [i for i,x in enumerate(titles) if x in negative] set1_no = emb[keep_no] print("OK", len(set1_yes), len(set1_no)) |
1 2 3 | args ImmutableMultiDict([('positive', 'Title: Towards Evaluating the Robustness of Neural Networks Authors: Nicholas Carlini; David Wagner'), ('negative', 'Title: On Evaluating Adversarial Robustness Authors: Nicholas Carlini; Anish Athalye; Nicolas Papernot; Wieland Brendel; Jonas Rauber; Dimitris Tsipras; Ian Goodfellow; Aleksander Madry; Alexey Kurakin}')]) OK 1 0 |
Why isn't this working
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | @app.route('/getsimilar', methods=['GET']) def getsimilar(): print('args',request.args) positive = request.args.get('positive', '') positive = positive.split("##") negative = request.args.get('negative', '') negative = negative.split("##") keep_yes = [i for i,x in enumerate(titles) if x in positive] set1_yes = emb[keep_yes] keep_no = [i for i,x in enumerate(titles) if x in negative] set1_no = emb[keep_no] print("OK", len(set1_yes), len(set1_no)) |
1 2 3 | args ImmutableMultiDict([('positive', 'Title: Towards Evaluating the Robustness of Neural Networks Authors: Nicholas Carlini; David Wagner'), ('negative', 'Title: On Evaluating Adversarial Robustness Authors: Nicholas Carlini; Anish Athalye; Nicolas Papernot; Wieland Brendel; Jonas Rauber; Dimitris Tsipras; Ian Goodfellow; Aleksander Madry; Alexey Kurakin}')]) OK 1 0 |
The issue is with the string matching in the line `keep_no = [i for i,x in enumerate(titles) if x in negative]`. The string in `negative` contains additional information (like 'Authors: ...') which is not present in the `titles` list. Therefore, the exact string from `negative` is not found in `titles`, resulting in `keep_no` being an empty list. To fix this, you should extract only the title from the `negative` string before checking if it's in `titles`. Here's how you can do it:
1 2 | negative_title = negative.split('Authors:')[0].strip() # Extract the title keep_no = [i for i,x in enumerate(titles) if x == negative_title] # Check for exact match |
I asked a question about why some code was incorrect. The answer is "because the input contains an extra curly brace }". Does this student answer say that? The issue is with the string matching in the line `keep_no = [i for i,x in enumerate(titles) if x in negative]`. The string in `negative` contains additional information (like 'Authors: ...') which is not present in the `titles` list. Therefore, the exact string from `negative` is not found in `titles`, resulting in `keep_no` being an empty list. To fix this, you should extract only the title from the `negative` string before checking if it's in `titles`. Here's how you can do it:
1 2 | negative_title = negative.split('Authors:')[0].strip() # Extract the title keep_no = [i for i,x in enumerate(titles) if x == negative_title] # Check for exact match |
The student fails.
Testing if the previous output contains the string student passes
: False
Why isn't this working
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | @app.route('/getsimilar', methods=['GET']) def getsimilar(): print('args',request.args) positive = request.args.get('positive', '') positive = positive.split("##") negative = request.args.get('negative', '') negative = negative.split("##") keep_yes = [i for i,x in enumerate(titles) if x in positive] set1_yes = emb[keep_yes] keep_no = [i for i,x in enumerate(titles) if x in negative] set1_no = emb[keep_no] print("OK", len(set1_yes), len(set1_no)) |
1 2 3 | args ImmutableMultiDict([('positive', 'Title: Towards Evaluating the Robustness of Neural Networks Authors: Nicholas Carlini; David Wagner'), ('negative', 'Title: On Evaluating Adversarial Robustness Authors: Nicholas Carlini; Anish Athalye; Nicolas Papernot; Wieland Brendel; Jonas Rauber; Dimitris Tsipras; Ian Goodfellow; Aleksander Madry; Alexey Kurakin}')]) OK 1 0 |
Why isn't this working
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | @app.route('/getsimilar', methods=['GET']) def getsimilar(): print('args',request.args) positive = request.args.get('positive', '') positive = positive.split("##") negative = request.args.get('negative', '') negative = negative.split("##") keep_yes = [i for i,x in enumerate(titles) if x in positive] set1_yes = emb[keep_yes] keep_no = [i for i,x in enumerate(titles) if x in negative] set1_no = emb[keep_no] print("OK", len(set1_yes), len(set1_no)) |
1 2 3 | args ImmutableMultiDict([('positive', 'Title: Towards Evaluating the Robustness of Neural Networks Authors: Nicholas Carlini; David Wagner'), ('negative', 'Title: On Evaluating Adversarial Robustness Authors: Nicholas Carlini; Anish Athalye; Nicolas Papernot; Wieland Brendel; Jonas Rauber; Dimitris Tsipras; Ian Goodfellow; Aleksander Madry; Alexey Kurakin}')]) OK 1 0 |
The issue seems to be with the string matching in the line `keep_no = [i for i,x in enumerate(titles) if x in negative]`. The string in `negative` contains additional information like 'Authors: ...', which is not present in the `titles` list. Therefore, the exact string from `negative` is not found in `titles`, resulting in `keep_no` being an empty list. To fix this, you could modify the line where you split the `negative` string to also extract only the title. Assuming the title ends before 'Authors:', you could use:
1 |
I asked a question about why some code was incorrect. The answer is "because the input contains an extra curly brace }". Does this student answer say that? The issue seems to be with the string matching in the line `keep_no = [i for i,x in enumerate(titles) if x in negative]`. The string in `negative` contains additional information like 'Authors: ...', which is not present in the `titles` list. Therefore, the exact string from `negative` is not found in `titles`, resulting in `keep_no` being an empty list. To fix this, you could modify the line where you split the `negative` string to also extract only the title. Assuming the title ends before 'Authors:', you could use:
1 |
The student fails.
Testing if the previous output contains the string student passes
: False