Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions 01_intro/hello_world/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ solution = [
"solution/script.py",
]



1 change: 0 additions & 1 deletion 03_classes/carpark_multiple_inheritance/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,3 @@ solution = [
"solution/electric_car.py",
"solution/hybrid_car.py",
]

25 changes: 25 additions & 0 deletions 04_llm/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Mandatory. This slug will be used for the URL of the assignment.
# ACCESS will refuse to import or update the course if the course/assignment slug is already taken by another assignment.
slug = "llm"

# Mandatory.
# Assignments will be invisible to regular users until the start date.
# Users will be able to submit solutions between the start and end date.
# After the end date, users will be able to see the assignment and run code, but they may not submit solutions.
# They will also see files marked as "solution" in individual tasks.
start = 2023-01-01T13:00:00
end = 2028-01-01T13:00:00

# Mandatory. List of directory paths containing the tasks.
# ACCESS will show tasks in the order in which they are listed here.
"tasks" = [
"string_manipulation",
]

# Information for at least one language must be specified.
[information.en]
title = "String Manipulation in Python"

[information.de]
title = "Stringmanipulation in Python"

45 changes: 45 additions & 0 deletions 04_llm/string_manipulation/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
slug = "string_manipulation"


max_attempts = 6
refill = 43200 # 12 hours
max_points = 2

[information.en]
title = "String Manipulation in Python"
instructions_file = "instructions_en.md"

[evaluator]
docker_image = "python:latest"
run_command = "python -m task.script"
test_command = "python -m unittest discover -v task"
grade_command = "python -m grading.tests"

[llm]
submission = "task/explanation.md"
Comment thread
rnichi1 marked this conversation as resolved.
rubrics = 'rubrics/rubrics.toml'
examples = 'grading/examples.toml'
solution = 'solution/explanation.md'
cot = true
voting = 3
post = "grading/post.md"
temperature = 0.2 # Decides the randomness of the gpt model
model = "claude" # gpt or claude
Comment thread
rnichi1 marked this conversation as resolved.
Outdated
max_points = 1 # Max points for the sub-task that is passed to the model

[files]
visible = [
"task/script.py",
"task/explanation.md",
]
editable = [
"task/script.py",
"task/explanation.md",
]
grading = [
"grading/tests.py",
]
solution = [
"solution/script.py",
"solution/explanation.md",
]
7 changes: 7 additions & 0 deletions 04_llm/string_manipulation/grading/examples.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[[examples]]
answer = "Reversing word order and reversing characters both have O(n) complexity, but character reversal requires more operations per word, making it slightly less efficient in practice."
points = "{ \"R1\": 1, \"R2\": 1 }"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any way to simplify this for the task designer, i.e. use toml syntax instead of a string? Escaping things like this is a bit tedious.
Also: these are weights? Because the points below are 0.5 and 0.5 for R1 and R2.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I will try to change it to toml syntax. Also yes, you are right. It should be 0.5 for the examples for each rubric. These are points not weights. Thanks!


[[examples]]
answer = "Both operations have O(n) complexity because they process each character in the string."
points = "{ \"R1\": 1, \"R2\": 0 }"
1 change: 1 addition & 0 deletions 04_llm/string_manipulation/grading/post.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The student answer will not contain any code. This is expected, since you only need to grade the explanation according to the rubrics!
37 changes: 37 additions & 0 deletions 04_llm/string_manipulation/grading/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env python3

# Scaffolding necessary to set up ACCESS test
import sys
try: from universal.harness import *
except: sys.path.append("../../universal/"); from harness import *

# Grading test suite starts here

script = grading_import("task", "script")

class GradingTests(AccessTestCase):

def _test(self, sentence, expected):
actual = script.reverse_words(sentence)
self.hint(f"Reversal not correct for sentence='{sentence}'... expected result is '{expected}'!")
self.assertEqual(expected, actual)

def test_case1(self):
self._test("Hello World", "World Hello")

def test_case2(self):
self._test(" This is a test ", "test a is This")

def test_case3(self):
self._test("Python", "Python")

def test_case4(self):
self._test("", "")

def test_case5(self):
self._test("Hello, World!", "World! Hello,")

def test_case6(self):
self._test("123 456 789", "789 456 123")

TestRunner().run(AccessTestSuite(1, [GradingTests]))
11 changes: 11 additions & 0 deletions 04_llm/string_manipulation/instructions_en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# String Manipulation in Python

## Task Description

Your task is to implement a Python function called `reverse_words`. This function should take a single string input and return a string with the words in reverse order. For example:

- Input: `"Hello World"`
- Output: `"World Hello"`

Additionally, reflect on the differences in complexity between reversing the order of words in a sentence and reversing the characters within each word in the `explanation.md` file provided.
Which operation do you think is more computationally efficient, and why? Consider factors such as string manipulation methods and time complexity in your explanation. Provide examples to support your reasoning.
9 changes: 9 additions & 0 deletions 04_llm/string_manipulation/rubrics/rubrics.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[[rubrics]]
id = "R1"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it even necessary to have rubric IDs or could they be parsed in the order they appear?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Ids help the model understand the examples. Without them, it would be harder to tell which rubric was correctly solved for each example, especially when there are more than just 2 rubrics.
This is also useful in order to avoid duplication of the rubric, since the model has the rubrics but might not immediately know to infer the order in an unstructured and fairly large prompt as ours. Also as an educator it's easier to give them a clear id like "asymptotically_equivalent" instead of an abstract "R2", in order to then more easily create examples for the llm. I will change the R1, R2 ids to be something more along those lines.

title = "Mentioned the time complexity of both operations is O(n)"
points = 0.5

[[rubrics]]
id = "R2"
title = "Explained that both are asymptotically equivalent but in practice, reversing characters is slower"
points = 0.5
16 changes: 16 additions & 0 deletions 04_llm/string_manipulation/solution/explanation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Reversing the order of words in a sentence and reversing the characters within each word have different complexities.

Time Complexity of Both Operations:
Reversing the word order involves splitting the string into a list of words O(n), reversing the list(O(n), and joining it back into a string O(n). This results in an overall complexity of O(n).
Reversing characters within each word requires iterating through each word and reversing it (O(m) per word, where m is the word length). Since this must be done for all words, the total complexity remains O(n).

Which is More Efficient and Why:
Both operations have an O(n) complexity, but reversing words is generally more efficient in practice because it operates at a higher level (list reversal), whereas reversing characters requires more fine-grained string manipulation.
If implemented using in-place reversal, reversing characters within each word can introduce additional overhead compared to simple list manipulation.

Example:

"Hello World" → "World Hello" (word order reversal)
"Hello World" → "olleH dlroW" (character reversal)

While both methods scale similarly, reversing characters involves additional operations per word, making it slightly more complex in practical execution.
3 changes: 3 additions & 0 deletions 04_llm/string_manipulation/solution/script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def reverse_words(sentence):
# Split the sentence into words, reverse the list, and join it back into a string
return ' '.join(sentence.split()[::-1])
1 change: 1 addition & 0 deletions 04_llm/string_manipulation/task/explanation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[comment]: <> (Add your solution here:)
7 changes: 7 additions & 0 deletions 04_llm/string_manipulation/task/script.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Task: Implement a function `reverse_words` that takes a string
# and returns the string with the order of words reversed.
# Example: "Hello World" -> "World Hello"

def reverse_words(sentence):
# TODO: Implement this function
pass
3 changes: 2 additions & 1 deletion config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ logo = "python.svg"
"assignments" = [
"01_intro",
"02_basics",
"03_classes"
"03_classes",
"04_llm",
]

# Mandatory. Determines who can see the course in ACCESS at any given time.
Expand Down