sakuexe commited on
Commit
ae85316
·
1 Parent(s): 7b0370e

initial commit

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ *.pdf filter=lfs diff=lfs merge=lfs -text
.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ __pycache__/
2
+ venv/
README.md CHANGED
@@ -1,12 +1,193 @@
1
- ---
2
- title: Thesizer
3
- emoji: 🏃
4
- colorFrom: red
5
- colorTo: yellow
6
- sdk: gradio
7
- sdk_version: 5.3.0
8
- app_file: app.py
9
- pinned: false
10
- ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # HAMK Thesis Assistant (Thesizer)
2
+
3
+ AI Project - 10.2024
4
+
5
+ ```
6
+ .----.
7
+ .---------. | == |
8
+ |.-"""""-.| |----|
9
+ || THE || | == |
10
+ || SIZER || |----|
11
+ |'-.....-'| |::::|
12
+ `"")---(""` |___.|
13
+ /:::::::::::\" _ "
14
+ /:::=======:::\`\`\
15
+ `"""""""""""""` '-'
16
+ ```
17
+
18
+ **Thesizer** is a fine-tuned LLM that is trained to assist with authoring Thesis'.
19
+ It is specifically trained and tuned to guide the user using HAMK's thesis
20
+ standards and guidelines [Thesis - HAMK](https://www.hamk.fi/en/student-pages/planning-your-studies/thesis/).
21
+ The goal of this is to make the process of writing a thesis easier, by helping
22
+ the user using spoken language, so that it will be easier for the user to find
23
+ help on the more technical aspects of writing a thesis. This way the user can
24
+ focus on what is the most important. The actual content of the Thesis.
25
+
26
+ This project is part of HAMK's `Development of AI Applications` -course. The
27
+ idea for the project spawned from the overwhelming feeling that all of the
28
+ different guidelines and learning documents there are for writing a thesis using
29
+ the standards of HAMK. Thesizer takes those documents and fine-tunes itself so
30
+ that it will be able to provide useful information and help the user. It is kind
31
+ of like a spoken language search engine for thesis writing technicalities.
32
+
33
+
34
+ ## Table of contents
35
+
36
+ 1. [Running the model](#Running-the-model)
37
+ 2. [Documentation](#Documentation)
38
+
39
+ 1. [The development process](#The-development-process)
40
+ - [Planning](#Planning)
41
+ - [Creating the model](#Creating-the-model)
42
+ 2. [Tools used](#Tools-used)
43
+ 3. [Challenges](#Challenges)
44
+
45
+ 3. [Dependencies](#Dependencies)
46
+ 3. [Helpful links](#Helpful-links)
47
+
48
+
49
+ ### Running the model
50
+
51
+ 1. **Install all of the dependencies**
52
+
53
+ The guide to this is in the [Dependencies](#Dependencies)-section.
54
+
55
+ 2. **Run the model**
56
+
57
+ ```bash
58
+ python3 thesizer_rag.py
59
+ # give a prompt
60
+ python3 thesizer_rag.py "mikä on abstract sivu?"
61
+ ```
62
+
63
+ ![thesizer web interface](./readme_images/helpWithThesis2.png)
64
+
65
+ ## Documentation
66
+
67
+
68
+ ### 1. The development process
69
+
70
+ #### Planning
71
+
72
+ The development process started after we had come to an agreement on the project.
73
+ We then tasked everyone to go and research what Hugging Face transformers would
74
+ be suitable as a base for our Fine-Tuned model.
75
+
76
+ Some of the models considered:
77
+
78
+ _General LLMs_
79
+
80
+ - [google-bert/bert-base-multilingual-cased](https://huggingface.co/google-bert/bert-base-multilingual-cased)
81
+ - [meta-llama/Llama-3.2-11B-Vision-Instruct](https://huggingface.co/meta-llama/Llama-3.2-11B-Vision-Instruct)
82
+ - [google/gemma-2-2b](https://huggingface.co/google/gemma-2-2b)
83
+
84
+ _Translation models_
85
+
86
+ - [facebook/mbart-large-50-one-to-many-mmt](https://huggingface.co/facebook/mbart-large-50-one-to-many-mmt)
87
+
88
+ #### Creating the model
89
+
90
+ As a base for the RAG model, we used this learning material from the Hugging
91
+ Face documentation: [Simple RAG for GitHub issues using Hugging Face Zephyr and LangChain](https://huggingface.co/learn/cookbook/rag_zephyr_langchain)
92
+
93
+
94
+ ### 2. Tools used
95
+
96
+ **LangChain**
97
+
98
+ Thesizer uses [LangChain](https://www.langchain.com/langchain) as the base
99
+ framework for our RAG application. It provided easy and straight forward
100
+ way for us to give a pre-trained llm model context awareness.
101
+
102
+ The documents that were used for the context awareness are all located in the
103
+ [learning_material](./learning_material/) -folder. They are mostly in finnish,
104
+ with some being in english. You can clone this repository and use your own
105
+ documents instead if you would like to see how it works and adapts to the
106
+ contents of the folder.
107
+
108
+ **Hugging Face**
109
+
110
+ The models used by thesizer are fetched from [HuggingFace](https://huggingface.co/models).
111
+ They are then used with `HuggingFacePipeline` package, which provides very easy
112
+ interaction with the models.
113
+
114
+ **FAISS**
115
+
116
+ FAISS is a highly efficient vector database, that also provides fast similiarity
117
+ searching of the data inside of it. FAISS supports CUDA and is written in C++.
118
+ Because of this, it also needs to be downloaded specifically to the user's
119
+ hardware, in the same way that pytorch needs to be.
120
+ [FAISS - ai.meta.com](https://ai.meta.com/tools/faiss/)
121
+
122
+ Thesizer uses FAISS for managing all of the documentation. It also uses
123
+ similiarity searching to find content from these files that match the user's query.
124
+
125
+ All of the FAISS processing is done asynchronously, so that theoretically it could
126
+ be passed more documentation during runtime without affecting the other users
127
+ processing time.
128
+
129
+ ### 3. Challenges
130
+
131
+
132
+ ## Dependencies
133
+
134
+ If the requirements.txt does not work, you can try installing the dependcies
135
+ using the following commands.
136
+
137
+ 0. **Create a virtual environment**
138
+
139
+ ```bash
140
+ # linux
141
+ python3 -m venv venv
142
+ source venv/bin/activate
143
+ # windows
144
+ python -m venv venv
145
+ .\venv\Scripts\Activate.ps1
146
+ ```
147
+
148
+ 1. **Install Pytorch that matches your machine**
149
+
150
+ Get the installation command from this website: [Start Locally | PyTorch](https://pytorch.org/get-started/locally/)
151
+
152
+ 2. **Install FAISS**
153
+
154
+ ```bash
155
+ # if you have a gpu
156
+ pip install faiss-gpu-cu12 # CUDA 12.x
157
+ pip install faiss-gpu-cu11 # CUDA 11.x
158
+ # if you only have a cpu
159
+ pip install faiss-cpu
160
+ ```
161
+
162
+ 3. **Install universal pip packages**
163
+
164
+ ```bash
165
+ pip install transformers accelerate bitsandbytes sentence-transformers langchain \
166
+ langchain-community langchain-huggingface pypdf bs4 lxml nltk gradio "unstructured[md]"
167
+ ```
168
+
169
+ 4. **Log into your Hugging Face account**
170
+
171
+ If you are prompted to log in, follow the instructions of the prompt.
172
+ You can figure it out.
173
+
174
+ > [!NOTE]
175
+ > If there are problems or the process feels complicated, add your own
176
+ > guide right here and replace this note.
177
+
178
+
179
+ ## Helpful links
180
+
181
+ Are you interested in finding out more and digging deeper? Here are some of the
182
+ sources that we used when creating this project.
183
+
184
+ Some links can also be found within the code comments, so that you can find them
185
+ near where they are used. Locality of behaviour babyyy.
186
+
187
+ **RAG & LangChain**
188
+
189
+ - Loading PDF files with LangChain and PyPDF | [How to load PDFs - LangChain](https://python.langchain.com/docs/how_to/document_loader_pdf/)
190
+ - Loading HTML files with LangChain and BeautifulSoup4 | [How to load HTML - LangChain](https://python.langchain.com/docs/how_to/document_loader_html/)
191
+ - Loading Markdown files with LangChain and unstructured | [How to load Markdown](https://python.langchain.com/docs/how_to/document_loader_markdown/)
192
+ - Asynchronous FAISS | [Faiss \(async\) - LangChain](https://python.langchain.com/docs/integrations/vectorstores/faiss_async/)
193
+ - Retriving data from a vectorstore | [How to use a vectorstore as a retriever - LangChain](https://python.langchain.com/docs/how_to/vectorstore_retriever/)
app.py ADDED
@@ -0,0 +1,207 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # the following code is collected from this hugging face tutorial
2
+ # https://huggingface.co/learn/cookbook/rag_zephyr_langchain
3
+ # langchain
4
+ from typing import TypedDict
5
+ from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
6
+ from langchain_core.messages import AIMessage, HumanMessage, SystemMessage
7
+ from langchain_core.output_parsers import StrOutputParser
8
+ from langchain_core.runnables import RunnablePassthrough
9
+ from langchain_huggingface import HuggingFacePipeline
10
+ # huggingface
11
+ from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
12
+ from transformers import pipeline
13
+ # pytorch
14
+ import torch
15
+ # gradio
16
+ import gradio as gr
17
+ # stdlib
18
+ from asyncio import sleep
19
+ # local
20
+ from vector_store import get_document_database
21
+
22
+
23
+ class ChatMessage(TypedDict):
24
+ role: str
25
+ metadata: dict
26
+ content: str
27
+
28
+
29
+ # MODEL_NAME = "meta-llama/Llama-3.2-3B"
30
+ # MODEL_NAME = "google/gemma-7b"
31
+ MODEL_NAME = "google/gemma-2-2b-it"
32
+
33
+ # bnb_config = BitsAndBytesConfig(
34
+ # load_in_4bit=True,
35
+ # bnb_4bit_use_double_quant=True,
36
+ # bnb_4bit_quant_type="nf4",
37
+ # bnb_4bit_compute_dtype=torch.bfloat16
38
+ # )
39
+
40
+ model = AutoModelForCausalLM.from_pretrained(
41
+ MODEL_NAME,
42
+ # quantization_config=bnb_config,
43
+ device_map="auto",
44
+ torch_dtype=torch.bfloat16
45
+ )
46
+
47
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
48
+
49
+ text_generation_pipeline = pipeline(
50
+ model=model,
51
+ tokenizer=tokenizer,
52
+ task="text-generation",
53
+ temperature=0.2,
54
+ do_sample=True,
55
+ repetition_penalty=1.1,
56
+ return_full_text=True,
57
+ max_new_tokens=400,
58
+ )
59
+
60
+ llm = HuggingFacePipeline(pipeline=text_generation_pipeline)
61
+
62
+
63
+ def generate_prompt(message_history: list[ChatMessage], max_history=5):
64
+ # creating the prompt template in the shape of a chat prompt
65
+ # this is done so that it could be easily expanded
66
+ # https://www.mirascope.com/post/langchain-prompt-template
67
+ prompt_template = ChatPromptTemplate([
68
+ ("system", """You are 'thesizer', a HAMK thesis assistant.
69
+ You will help the user with technicalities on writing a thesis
70
+ for hamk. If you can't find the answer from the context given to you,
71
+ you will tell the user that you cannot assist with the specific topic.
72
+ You speak both Finnish and English by following the user's language.
73
+ Continue the conversation with a single response from the AI."""),
74
+ ("system", "{context}"),
75
+ ])
76
+
77
+ # include the examples in the prompt if the conversation is starting
78
+ if len(message_history) < 4:
79
+ prompt_template.append(
80
+ ("assistant", "Hei! Kuinka voin auttaa opinnäytetyösi kanssa?"),
81
+ )
82
+ prompt_template.append(
83
+ ("assistant", "Hello! How can I help you with authoring your thesis?"),
84
+ )
85
+
86
+ # add chat messages here (only include up to the max amount)
87
+ for message in message_history[-max_history:]:
88
+ prompt_template.append(
89
+ (message["role"], message["content"])
90
+ )
91
+
92
+ # this is here so that the stupid thing wont start roleplaying as the user
93
+ # and therefore making up the conversation
94
+ prompt_template.append(
95
+ ("assistant", "<RESPONSE>:")
96
+ )
97
+
98
+ return prompt_template
99
+
100
+
101
+ async def generate_answer(message_history: list[ChatMessage]):
102
+ # generate a vector store
103
+ db = await get_document_database("learning_material/*/*/*")
104
+
105
+ # initialize the similarity search
106
+ n_of_best_results = 4
107
+ retriever = db.as_retriever(
108
+ search_type="similarity", search_kwargs={"k": n_of_best_results})
109
+
110
+ prompt = generate_prompt(message_history, max_history=5)
111
+
112
+ # create the pipeline for generating a response
113
+ # RunnablePassthrough handles the invoke parameters
114
+ retrieval_chain = (
115
+ {"context": retriever, "user_input": RunnablePassthrough()}
116
+ | prompt
117
+ | llm
118
+ | StrOutputParser()
119
+ )
120
+
121
+ # fetch the context using the latest message as the fetch string
122
+ user_input = message_history[-1]["content"]
123
+ response = retrieval_chain.invoke(user_input)
124
+
125
+ # # debugging
126
+ # print("=====raw response=====")
127
+ # print(response)
128
+
129
+ # get the next response from the AI
130
+ # first parse until the last user input and then get the first response
131
+ parsed_answer = response.split(
132
+ str(user_input)
133
+ ).pop().split("<RESPONSE>:", 1).pop().strip()
134
+
135
+ print(repr(parsed_answer))
136
+
137
+ # replace newlines with br tags, since the gr.chatbot does not work
138
+ # well with newlines
139
+ return parsed_answer.replace("\n\n", "<br>")
140
+
141
+
142
+ def update_chat(user_message: str, history: list):
143
+ return "", history + [{"role": "user", "content": user_message}]
144
+
145
+
146
+ async def handle_conversation(
147
+ history: list[ChatMessage],
148
+ characters_per_second=80
149
+ ):
150
+ bot_message = await generate_answer(history)
151
+ new_message: ChatMessage = {"role": "assistant",
152
+ "metadata": {"title": None},
153
+ "content": ""}
154
+ history.append(new_message)
155
+ for character in bot_message:
156
+ history[-1]['content'] += character
157
+ yield history
158
+ await sleep(1 / characters_per_second)
159
+
160
+
161
+ def create_interface():
162
+ with gr.Blocks() as interface:
163
+ gr.Markdown("# 📄 Thesizer: HAMK Thesis Assistant")
164
+ gr.Markdown("Ask for help with authoring the HAMK thesis!")
165
+
166
+ gr.Markdown("## Chat interface")
167
+
168
+ with gr.Column():
169
+ chatbot = gr.Chatbot(type="messages")
170
+
171
+ with gr.Row():
172
+ user_input = gr.Textbox(
173
+ label="You:",
174
+ placeholder="Type your message here...",
175
+ show_label=False
176
+ )
177
+ send_button = gr.Button("Send")
178
+
179
+ # handle the messages being sent
180
+ send_button.click(
181
+ fn=update_chat,
182
+ inputs=[user_input, chatbot],
183
+ outputs=[user_input, chatbot],
184
+ queue=False
185
+ ).then(
186
+ fn=handle_conversation,
187
+ inputs=chatbot,
188
+ outputs=chatbot
189
+ )
190
+
191
+ # pressing enter instead of the button
192
+ user_input.submit(
193
+ fn=update_chat,
194
+ inputs=[user_input, chatbot],
195
+ outputs=[user_input, chatbot],
196
+ queue=False
197
+ ).then(
198
+ fn=handle_conversation,
199
+ inputs=chatbot,
200
+ outputs=chatbot
201
+ )
202
+
203
+ return interface
204
+
205
+
206
+ if __name__ == "__main__":
207
+ create_interface().launch()
learning_material/README.md ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Lähteet
2
+
3
+ Lähteitä opinnäytetyöhön ohjaavaan materiaaliin ja HAMKin ohjeistuksiin.
4
+ Lähteissä myös yleisiä ohjeita sekä word pohjien PDF kopiot.
5
+
6
+ ## HAMK ohjeistus
7
+
8
+ - [Raportin_rakenne_paivitetty_kevät2022](https://app.widgets.thinglink.com/accessibility/1510308362439360513)*
9
+ - [Opinnäyetyö pikalinkit](https://www.hamk.fi/opiskelijalle/opintojen-suunnittelu/opinnaytetyo/)
10
+ - [Tutkimusraportin ja opinnäytetyön kirjoittajan tarkistuslista](https://hameenamk-my.sharepoint.com/:p:/g/personal/lmustonen_hamk_fi/EURjvZwdtRpGtPrraY7tXtgBZ-ywpp39CjfseKQUnAMaWQ?e=q0TJrB)
11
+ - [Kielenhuollon tarkistuslista](https://hameenamk-my.sharepoint.com/:p:/g/personal/lmustonen_hamk_fi/Ee1wmt9G26NJt2GH_PsjBtMBs-ql62l511QIT5Pv57zqKQ?e=vUNInc)
12
+
13
+ ## Teknisiä yksityiskohtia
14
+
15
+ - [HAMK Lähdeviiteopas Osa 1: Perusteet](https://www.hamk.fi/wp-content/uploads/2023/11/Lahdeviiteopas-osa-1-perusteet-1.pdf)
16
+ - [HAMK Lähdeviiteopas Osa 2: Esimerkit](https://www.hamk.fi/wp-content/uploads/2023/11/Lahdeviiteopas-osa-2-esimerkit-1.pdf)
17
+ - [Taulukot, kuviot ja kuvat tekstissä](https://hameenamk-my.sharepoint.com/:p:/g/personal/lmustonen_hamk_fi/EbjU1CG6SMBGvx--NVo2t4UBVFtPvRa3UDoZBxO-UkEsWQ?e=Pr7HmY)
18
+ - [Ohjeita ja esimerkkejä kuvien merkintään](https://hameenamk-my.sharepoint.com/:w:/g/personal/lmustonen_hamk_fi/EZq3oBSYzDVAhUirgcGK6bMBKKGTGCUiqwToPdheUx79hw?e=0e7XmH)
19
+
20
+ ## Opinnäytetyön prosessi
21
+
22
+ - [Ennen opinnäytetyön aloittamista](https://www.hamk.fi/opiskelijalle/opintojen-suunnittelu/opinnaytetyo/ennen-opinnaytetyon-aloittamista/)*
23
+ - [Opinnäytetyön suunnittelu ja toteutus](https://www.hamk.fi/opiskelijalle/opintojen-suunnittelu/opinnaytetyo/opinnaytetyon-suunnittelu-ja-toteutus/)*
24
+ - [Opinnäytetyön viimeistely](https://www.hamk.fi/opiskelijalle/opintojen-suunnittelu/opinnaytetyo/opinnaytetyon-viimeistely/)*
25
+
26
+ ## Yleisiä opinnäytetyö ohjeita
27
+
28
+ - [Tieteellinen teksti](https://hameenamk-my.sharepoint.com/:p:/g/personal/lmustonen_hamk_fi/Ed9tXZIP_FZMlbcOg5LiYkMBqSNIRDB6kwPf1qhGARW0SA?e=jvPdan)
29
+ - [JAMKin ohjeita opinnäytetyöhön, kirjoittamisesta, tiedonhankinnasta, yms. hyödyllistä](https://help.jamk.fi/raportointiohje/fi/)*
30
+ - [APA style referencing guidelines](https://apastyle.apa.org/style-grammar-guidelines/references)*
31
+
32
+ ## Word pohjat
33
+
34
+ - [Opinnäytetyö-pohja](https://www.hamk.fi/wp-content/uploads/2024/01/Thesis-Template.dotx)
35
+ - [Opinnäytetyön liitepohja](https://www.hamk.fi/wp-content/uploads/2024/10/HAMK-thesis-appendix-template-2024-1.dotx)
36
+
37
+ Linkit jotka ovat merkattuna merkillä "*" eivät ole tiedostoina tallessa, sillä ne ovat digitaalisia lähteitä.
38
+ Nämä lähteet voidaan kopioida myöhemmin markdown tiedostoihin.
learning_material/english/pdf/clear-english-tips-translators_en.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:08b9a099cdd9f8cc77710ba2563c1bbb1744478a9a4fecebbfd646d6ff8b973f
3
+ size 577492
learning_material/english/pdf/thesis_appendix_template_2024.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1c78ca102b46d45083a62002732802a7e2a1c919290c002c699c3232f918e3dc
3
+ size 23643
learning_material/english/pdf/thesis_template.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:08ef1ead4e8e1f7d6168e2b834237ef27890dc821998845ddf811bbebffae367
3
+ size 200698
learning_material/english/thesis_process_stages.md ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Stages of the Thesis Process
2
+
3
+ [The link to the graphic](https://www.thinglink.com/scene/1649820289044840451)
4
+
5
+ ## Wihi
6
+
7
+ The thesis process progresses with the Wihi system in Pakki. You start your thesis
8
+ in Wihi by creating a topic proposal. After you have been assigned a supervisor,
9
+ you can use Wihi to plan your schedule for completing the thesis. You use Wihi
10
+ to send messages to the thesis supervisor and the commissioner, so the different
11
+ stages of the process are stored in one place. The work will also be published
12
+ and evaluated in Wihi. Read the
13
+ [Wihi instructions for students](https://www.hamk.fi/wp-content/uploads/2024/01/student-Wihi-instructions.pdf)
14
+ for more information.
15
+
16
+ ## Open Badge of a thesis expert
17
+
18
+ An Open Badge of a thesis expert is completed at the beginning of the thesis
19
+ process at the latest, and a screen capture of the badge is sent to the
20
+ supervisor via a Wihi message. The badge is completed in the
21
+ [Thesis Open Badge Moodle](https://learn.hamk.fi/course/view.php?id=7618).
22
+
23
+ ## Seminars
24
+
25
+ You will hold three presentations i.e. seminars related to your work:
26
+
27
+ - a planning seminar, where you present the framework of your work, a preliminary table
28
+ of contents and the knowledge base
29
+ - an interim seminar, where the reporting process is well underway, and you have written
30
+ the main contents
31
+ - a final seminar, where you present your finished thesis.
32
+
33
+ The practicalities for the planning and interim seminars, such as the presentation
34
+ method and the audience, are determined by the degree programme. Towards the end
35
+ of your studies, you will familiarise yourself in advance with interim and final
36
+ seminar events. This includes your degree programme’s seminar and registration
37
+ practices as well as scheduling.
38
+
39
+ ## Acting as an opponent
40
+
41
+ Each thesis will have an opponent, and each student will in turn act as an opponent
42
+ for another student’s thesis. This usually takes place at the interim seminar stage.
43
+ The opponents focus on both the produced text and the presentation. See your degree
44
+ programme's instructions regarding opponent selection and scheduling for more information.
45
+
46
+ ## English language check
47
+
48
+ The thesis will be submitted to the English teacher for comments via Wihi already at
49
+ the interim stage. In addition, the English teacher will give a numerical assessment
50
+ of the finished thesis in Wihi. The English teacher will check the abstract,
51
+ which is delivered together with the Finnish summary via Wihi in the final stage of
52
+ the process. Reserve three weeks for the evaluation of the thesis and the inspection
53
+ of the abstract.
54
+
55
+ Send the file for commenting by downloading the file and clicking "Send for external comments".
56
+ You can find the feedback you received in the section "Statements by interest groups".
57
+ See the contact details of your degree programme’s English teachers in the programme-specific
58
+ instructions.
59
+
60
+ ## Maturity test
61
+
62
+ Instructions for the maturity test can be found on
63
+ [HAMK’s thesis page](https://www.hamk.fi/planning-studies/final-thesis/?lang=en)
64
+ (Appendix 6). You must register for the maturity test in accordance with your own degree programme.
65
+
66
+ ## Feedback
67
+
68
+ It is important that you give the student's feedback on the thesis process after
69
+ completing your work. Once your thesis has been evaluated, you will receive an
70
+ email with a link to the feedback survey via Wihi.
71
+
72
+ _Last modified: Friday, 9 February 2024, 2:56 PM_
73
+
74
+ [link to the original moodle page](https://learn.hamk.fi/mod/page/view.php?id=430392)
learning_material/english/thesis_template_instructions.md ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Instructions for Using HAMK Thesis Template
2
+
3
+ This page contains a collection of Word instructions produced by Microsoft
4
+ to help you use the document template for HAMK’s thesis. The Microsoft Web
5
+ site provides instructions on the same issues for versions of Windows and
6
+ iOS operating systems.
7
+
8
+ HAMK Thesis template, [Final Thesis page](https://www.hamk.fi/planning-studies/final-thesis/?lang=en)
9
+
10
+ ## Styles and Table of Contents
11
+
12
+ - [Apply styles](https://support.microsoft.com/en-us/office/apply-styles-f8b96097-4d25-4fac-8200-6139c8093109)
13
+ - [Insert a table of contents](https://support.microsoft.com/en-us/office/insert-a-table-of-contents-882e8564-0edb-435e-84b5-1d8552ccf0c0)
14
+ - [Update a table of contents](https://support.microsoft.com/en-us/office/update-a-table-of-contents-6c727329-d8fd-44fe-83b7-fa7fe3d8ac7a)
15
+
16
+ ## Sections and Different Headers
17
+
18
+ [Insert, delete, or change a section break](https://support.microsoft.com/en-us/office/insert-delete-or-change-a-section-break-0eeae2d6-b906-42d3-a1bd-7e77ca8ea1f3)
19
+ [Different page numbers to different sections](https://support.microsoft.com/en-us/office/add-different-page-numbers-or-number-formats-to-different-sections-bb4da2bd-1597-4b0c-9e91-620615ed8c05)
20
+ [Add page numbers](https://support.microsoft.com/en-us/office/insert-page-numbers-9f366518-0500-4b45-903d-987d3827c007)
21
+ [Remove page numbers](https://support.microsoft.com/en-us/office/remove-page-numbers-d79e5090-c8f7-4e24-ab97-c36cfeb8d85b)
22
+ [Start page numbering later in your document](https://support.microsoft.com/en-us/office/start-page-numbering-later-in-your-document-c73e3d55-d722-4bd0-886e-0b0bd0eb3f02)
23
+
24
+ ## Better Usability
25
+
26
+ [Add alternative text to a picture, chart, or other object](https://support.microsoft.com/en-us/office/add-alternative-text-to-a-shape-picture-chart-smartart-graphic-or-other-object-44989b2a-903c-4d9a-b742-6a75b451c669)
27
+ [Improve accessibility](https://support.microsoft.com/en-us/office/improve-accessibility-with-the-accessibility-checker-a16f6de0-2f39-4a2b-8bd8-5ad801426c7f)
28
+ [Check document properties](https://support.microsoft.com/en-us/office/view-or-change-the-properties-for-an-office-file-21d604c2-481e-4379-8e54-1dd4622c6b75)
29
+
30
+ ## Finishing Your Document
31
+
32
+ [If you have extra pages in your document](https://support.microsoft.com/en-us/office/remove-a-page-break-e696a217-adc7-4ef3-977b-de0c3d87b762?redirectSourcePath=%252ffi-fi%252foffice%252fsivunvaihtojen-poistaminen-wordissa-9c3a7916-7d10-4cac-b4ab-ea8a671fe3c9&ui=en-US&rs=en-001&ad=US)
33
+
34
+ ## References, Citations and Sources
35
+
36
+ [Add, format, and delete captions](https://support.microsoft.com/en-us/office/add-format-or-delete-captions-in-word-82fa82a4-f0f3-438f-a422-34bb5cef9c81)
37
+ [Create a cross-reference](https://support.microsoft.com/en-us/office/create-a-cross-reference-300b208c-e45a-487a-880b-a02767d9774b)
38
+ [Create a bibliography, citations and references](https://support.microsoft.com/en-us/office/create-a-bibliography-citations-and-references-17686589-4824-4940-9c69-342c289fa2a5)
39
+
40
+ ## Combining PDF files
41
+
42
+ [Combining PDF files in Adobe online service](https://acrobat.adobe.com/link/acrobat/combine-pdf?x_api_client_id=adobe_com&x_api_client_location=combine_pdf)
43
+
44
+ Source:
45
+
46
+ [Original URL to the guide](https://digipedaohjeet.hamk.fi/ohje/instructions-for-using-hamk-thesis-template/?lang=en)
learning_material/finnish/html/Ennen opinnäytetyön aloittamista - HAMK.html ADDED
The diff for this file is too large to render. See raw diff
 
learning_material/finnish/html/Opinnäytetyön suunnittelu ja toteutus - HAMK.html ADDED
The diff for this file is too large to render. See raw diff
 
learning_material/finnish/html/Opinnäytetyön viimeistely - HAMK.html ADDED
The diff for this file is too large to render. See raw diff
 
learning_material/finnish/pdf/asiakirjamallin_kayttoohje.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:44cecd5b97a2b2cb596935f1299ffcb443d7ed3c8aa74798b0791d22b3f8929d
3
+ size 1086855
learning_material/finnish/pdf/kielenhuollon_tarkistuslista.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0170322c8ffaa0b4a788655dc56f650fe9c997a69cdf26bbbedb55a5b2ef19be
3
+ size 640914
learning_material/finnish/pdf/kuvat_taulukot_koodit_ohje.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6cb4ce237e8f167b6bbb753660846d8a964af71532e57904c4e853ef6d1c6e97
3
+ size 8325445
learning_material/finnish/pdf/lahdeviiteopas-esimerkit.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:74d78f023fce43b3e30dc45f817fe54c4f69ebb1b76a73822a0d701e444b4110
3
+ size 746962
learning_material/finnish/pdf/lahdeviiteopas-perusteet.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:211fa6fa93dd04618ea3852610bb6c74260e2300002c8ae4d4eab6c82445e6f6
3
+ size 427503
learning_material/finnish/pdf/opinnäytetyön_kirjoittajan_tarkistuslista.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f889763d9f5162cb0f59aa9f437c2a703493d217c41ac16c458869666aeef726
3
+ size 745702
learning_material/finnish/pdf/taulukot_kuvat_ja_numerotulokset_tekstissa.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b77fec84c0ad60f78343c4a6b4e19d508a63601e2edccaea8db465b26a52693a
3
+ size 274476
learning_material/finnish/pdf/tieteellinen_kirjoittaminen_lyhennetty.pdf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:bf34748caae0f693013a48f6d5f2235c6913b12d3bc5e963d0faed53af756d6d
3
+ size 2737060
learning_material/finnish/raportin_rakenne.md ADDED
@@ -0,0 +1,234 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Opinnäytetyön esimerkki (TEOS)
2
+
3
+ ## Otsikko ja alaotsikko
4
+
5
+ Työlle annetaan aina otsikko. Jos otsikkoa haluaa tarkentaa, työlle voidaan
6
+ antaa alaotsikko. Jollei alaotsikkoa kirjoiteta, rivi poistetaan asiakirjasta.
7
+
8
+ ## \[Tutkinnon\] opinnäytetyö
9
+
10
+ Tähän kirjoitetaan, mitä tutkintoa suoritetaan ja minkälaisesta työstä on kyse.
11
+ Esimerkiksi: Ammattikorkeakoulututkinnon harjoitustyö tai Ylemmän
12
+ ammattikorkeakoulututkinnon opinnäytetyö
13
+
14
+ ## Koulutuksen nimi, kampus
15
+
16
+ Tähän kirjoitetaan suoritettavan koulutuksen nimi kokonaisuudessaan.
17
+ Esimerkiksi: Tieto- ja viestintätekniikka, insinööri (AMK) Rakennus- ja
18
+ yhdyskuntatekniikka, insinööri (AMK) Sähkö- ja automaatiotekniikka, insinööri
19
+ (AMK)
20
+
21
+ ## Lukukausi vuosi ja tekijän/tekijöiden nimet
22
+
23
+ Työn lukuvuosi tieto kirjoitetaan lyhyesti. Esimerkiksi Kevät 2021 Tämän
24
+ jälkeen kirjoitetaan tekijän tai tekijöiden nimet.
25
+
26
+ ## Tiivistelmäsivun tiedot
27
+
28
+ Kirjoita tähän tiedot (tutkinnon nimi, tekijöiden nimet, työn nimi) samassa
29
+ muodossa kuin kansilehdellä.
30
+
31
+ ## Ohjaajat
32
+
33
+ Tähän kirjoitetaan opinnäytetyön ohjaajan nimi. Ohjaajia voi olla useita ja
34
+ HAMKin ulkopuolisista organisaatioista. Kirjoita ensin aina HAMKin opinnäytetyön
35
+ ohjaaja ja sen jälkeen ulkopuolisen organisaation ohjaaja sekä tämän
36
+ organisaation nimi. Muista kysyä ulkopuolisen ohjaajan lupa nimen merkitsemiseen.
37
+
38
+ ## Tiivistelmä
39
+
40
+ Tiivistelmän pituus on 1 sivu ja se tiivistää koko työn sisällön. Tiivistelmä
41
+ kirjoitetaan passiivissa ja menneessä aikamuodossa (imperfektissä).
42
+ Johtopäätöksistä voi kertoa preesensissä.
43
+
44
+ ## Avainsanat
45
+
46
+ Avainsanat kirjoitetaan aakkosjärjestykseen tai tärkeysjärjestykseen ja ne
47
+ erotetaan toisistaan pilkulla. Vain ensimmäinen avainsana alkaa isolla
48
+ alkukirjaimella. Avainsanojen löytämiseen voi hyödyntää verkkosivua ai.finto.fi
49
+
50
+ [ai.into.fi](https://ai.finto.fi/?locale=en)
51
+
52
+ ## Sivut
53
+
54
+ Ensin merkitään sivumäärä ja sen jälkeen liitteiden määrä. Lähdeluettelon
55
+ viimeinen sivu on työn viimeinen numeroitava sivu. Näet sivumäärän siis
56
+ lähdeluettelon viimeisen sivun sivunumerosta.
57
+
58
+ ## Abstract-sivu
59
+
60
+ Abstract on tiivistelmän englanninkielinen versio. Jos työhön ei tule
61
+ abstract-sivua, se poistetaan asiakirjasta. Muutoin siihen kirjoitetaan
62
+ vastaavat tiedot englanniksi.
63
+
64
+ ## Sisällysluettelo
65
+
66
+ Sisällysluettelosta näkee otsikoiden nimestä työn keskeisen sisällön ja
67
+ rakenteen. On tärkeää varmistaa, että pääotsikot ja alaotsikot liittyvät
68
+ loogisesti toisiinsa. Asiakirjamallissa on valmiina Word-työkalulla luotu
69
+ sisällysluettelo. Tämä luettelo päivitetään, kun työ on valmis eikä sitä siis
70
+ kirjoiteta käsin.
71
+
72
+ ## Otsikot ja sivunumerot
73
+
74
+ Jokainen otsikko on numeroitu ja nimetty. Lähteet on ainoa numeroimaton otsikko.
75
+ Jos otsikkosi ei näy päivittämisen jälkeen sisällysluettelossa, tarkista että
76
+ sillä on oikea otsikkotyyli. Mikäli sisällysluettelossa näkyy numeroimattomia
77
+ otsikoita, olet joko muokannut otsikkotyyliä tai kopioinut tyylin muusta
78
+ asiakirjasta omaan työhösi. Tässä tapauksessa tarkista, että käytät oikeanlaisia
79
+ tyyleja otsikoissa ja korjaa virheelliset tyylit tekstistäsi.
80
+
81
+ ## Liiteluettelo
82
+
83
+ Lopuksi listataan vielä työn liitteet. Mikäli liitteitä ei ole, liiteluettelo
84
+ poistetaan.
85
+
86
+ ## Johdanto
87
+
88
+ Työn ensimmäinen luku on Johdanto. Sitä ei ole yleensä tarpeen jakaa alalukuihin.
89
+ Johdannon tarkoitus on johdattaa lukija tutkimusraportin tai opinnäytetyön
90
+ aihepiiriin. Johdannossa kerrotaan työn tavoitteet ja tarkoitus, muttei kerrota
91
+ tuloksia tai arvioida prosessia. Jos työssä on mukana useita tekijöitä,
92
+ johdannossa kerrotaan jokaisen osallisen vastuualueet.
93
+
94
+ ## Pääotsikko
95
+
96
+ Pääotsikko koostuu numerosta ja nimestä. Numeron jälkeen ei tule pistettä ja
97
+ otsikko alkaa isolla kirjaimella.
98
+
99
+ ## Toisen tason otsikko
100
+
101
+ Toisen tason otsikossa on kaksiosainen numerointi ja nimi. Tässä 2.1 tarkoittaa
102
+ toisen pääluvun ensimmäistä alalukua. Väliotsikoiden tulee selkeästi kuulua
103
+ pääotsikon alle.
104
+
105
+ ## Tekstiviite
106
+
107
+ Tekstiviitteen muoto on (tekijä, vuosi) Tekijällä tarkoitetaan kirjoittajaa,
108
+ organisaatiota tai julkaisijaa ja vuosi on lähteen julkaisuvuosi. Jos
109
+ viitataan koko kappaleeseen, viite tulee kappaleen jälkeen sulkuihin, eikä
110
+ siihen merkitä pistettä. Jos viitataan vain yhteen virkkeeseen, viite
111
+ kirjoitetaan sulkeisiin virkkeen sisään. Tekstiviitteen voi kirjoittaa myös
112
+ tekijäkeskeisesti. Tutustu huolellisesti HAMKin lähdeviiteoppaaseen
113
+ tekstiviitteiden ja lähteiden oikeinmerkitsemiseen.
114
+
115
+ ## Luvut
116
+
117
+ Jokainen luku muodostuu vähintään kahdesta kappaleesta. Työssä voi olla
118
+ päälukuja ilman alalukuja. Jos pääluvun alla halutaan käyttää alalukuja, niitä
119
+ täytyy olla vähintään kaksi.
120
+
121
+ ## Tyylit
122
+
123
+ Tyylipaletista löytyy valmiina eri tarkoituksiin muotoillut tekstit. Älä luo
124
+ tyylejä itse, vaan käytä asiakirjamallin valmiita tyylejä. Otsikko 1 on
125
+ päätason otsikko ja Otsikko 2 toisen tason otsikko. Leipäteksti kirjoitetaan
126
+ tyylillä Perusteksti tai Normaali.
127
+
128
+ ## Kuvat
129
+
130
+ Kaikilla kuvilla on numero ja otsikko. Numerointi tapahtuu automaattisesti
131
+ otsikoinnin yhteydessä. Otsikoinnin yhteydessä on hyvä muistaa, että
132
+ kuvaotsikon paikka on kohteen yläpuolella ja otsikon jälkeen tulee merkitä
133
+ myös kuvan lähdeviite. Ennen kuvan esiintymistä asiakirjassa, siitä täytyy
134
+ olla maininta tekstissä. Muista myös kirjoittaa kuvalle vaihtoehtoinen kuvaus.
135
+
136
+ ## Kuvaluettelo
137
+
138
+ Sisällysluettelon alle voi lisätä luettelon kuvista, taulukoista tai kaavoista.
139
+ Se voi olla hyödyllinen, jos raportissa on paljon kuvia, ja ne ovat
140
+ olennainen osa raportin sisältöä. Se ei kuitenkaan ole pakollinen.
141
+
142
+ ## Taulukko
143
+
144
+ Taulukon tulee olla hyvin yksinkertaistettu ja helppolukuinen. Ylimääräisten
145
+ tyhjien ruutujen esiintymistä tulee välttää. Taulukko tulee tehdä Wordin
146
+ taulukko työkalulla tai liittää esimerkiksi Excelistä linkitettynä. Taulukkoa
147
+ ei tule liittää kuvana asiakirjaan. Kuvien tapaan taulukolla on numero ja nimi.
148
+ Otsikointi tapahtuu samalla tavalla kuin kuville. Valitaan taulukko ja
149
+ Viittaukset välilehdeltä valitaan Lisää Otsikko. Otsikon paikka on valitun
150
+ kohteen yläpuolella. Muista merkitä myös taulukkoon lähde, mikäli taulukko ei
151
+ ole omaa tuotostasi. Lisää ohjeita taulukon tekemisestä löytyy
152
+ KvantiMOTV-sivuilta. Linkki alla.
153
+
154
+ [fsd.tuni.fi](https://www.fsd.tuni.fi/menetelmaopetus/raportointi/numerotulokset.html)
155
+
156
+ ## Kaavat
157
+
158
+ Myös kaavat numeroidaan ja otsikoidaan. Noudata samoja ohjeita kuin kuvien ja
159
+ taulukoiden kanssa. Kaavasta mainitaan ennen sen esiintymistä ja otsikon
160
+ paikka on kohteen yläpuolella.
161
+
162
+ ## Luettelot
163
+
164
+ Luetteloiden kirjoittamiseen käytetään luettelotyylejä. Tyylipaletista löytyy
165
+ tyylit numeroimattomalle ja numeroidulle luettelolle. Muista, että luetelma ei
166
+ voi aloittaa lukua tai muodostaa lukua yksinään.
167
+
168
+ ## Lopetusluku
169
+
170
+ Raportin viimeinen luku on kokoava lopetusluku. Sen otsikko voi olla
171
+ esimerkiksi Yhteenveto, Pohdinta tai Päätelmät. Lopetusluvussa kerrataan
172
+ tavoitteet, tulokset ja työn keskeinen sisältö. Peilaa johdannossa
173
+ kirjoittamaasi johdantoon.
174
+
175
+ ## Asiakirjamalli
176
+
177
+ Kaikki opintoihin kuuluvat raportit tehdään opinnäytetyön asiakirjamalliin.
178
+
179
+ [Hamkin opinnäytetyöohjeet](https://www.hamk.fi/opiskelijan-ohjeet/opinnaytetyo/)
180
+
181
+ ## Sivunumerointi
182
+
183
+ Sivunumerointi alkaa johdantosivulta ja päättyy lähdeluettelon viimeiseen
184
+ sivuun. Tämä tapahtuu asiakirjamallissa automaattisesti. Lisätessä ja
185
+ poistaessa sivuja on kuitenkin hyvä tarkistaa, ettei asiakirjan rakenteeseen
186
+ ja sivunumerointiin tule muutoksia.
187
+
188
+ ## Lähteet
189
+
190
+ Lähdeviiteopas löytyy samasta paikasta HAMKin nettisivuilta,kuin
191
+ asiakirjamallikin. Katso ohjeet lähdeluettelon, tekstiviitteiden ja
192
+ kuvaviitteiden tekemiseen lähdeviiteoppaasta.
193
+
194
+ [hamk.fi](https://www.hamk.fi/opiskelijan-ohjeet/opinnaytetyo/)
195
+
196
+
197
+ ## Viite
198
+
199
+ Kuviin ja taulukoihin merkitään lähdeviitteet aivan kuten referoituun
200
+ tekstiinkin. Jos kuva on oma, lähdettä ei tarvitse merkitä.
201
+
202
+ ## Lähteet
203
+
204
+ Lähteet aakkostetaan tekijän sukunimen tai tekijäorganisaation nimen mukaan.
205
+ Lähdeluettelossa olevat linkit tehdään toimiviksi, eli hyperlinkeiksi. Tutustu
206
+ tarkasti HAMKin lähdeviiteoppaaseen, kun teet lähdeluetteloa ja tekstiviitteitä.
207
+ Voit kirjoittaa lähdeluettelon käsin tai käyttämällä Wordin omaa
208
+ lähdeluettelotyökalua. Käytä työkalua vain, jos tunnet osaavasti käyttää sitä
209
+ oikein. Julkaisemattomat lähteet jätetään pois lähdeluettelosta. Niillä tulee
210
+ kuitenkin olla tekstiviite ja lähde tulee avata tekstissä selkeästi.
211
+ Julkaisemattomia lähteitä ovat esimerkiksi haastattelut, luennot, sähköpostit
212
+ ja intranetissä olevat tiedosto, sekä esimerkiksi suljetut oppimisympäristöt
213
+ kuten Moodle.
214
+
215
+ ## Liitteet
216
+
217
+ Liitteet numeroidaan ja nimetään. Liitteitä ei merkitä sisällysluetteloon,
218
+ mutta niiden oma luettelo löytyy sisällysluettelosivulta. Mikäli työhön ei
219
+ tule liitteitä, liiteluettelo poistetaan. Poista myös tyhjät liitesivut tai
220
+ jätä ne pois, kun viet asiakirjan PDF-tiedostoksi. Jokaiseen liitteeseen
221
+ viitataan tekstissä ja siihen viitataan numerolla. Esimerkiksi. "Kaikille
222
+ kyselyyn osallistuville opiskelijoille jaettiin liitteen 1 mukainen kysely
223
+ vapaa-ajan vietosta."
224
+
225
+ ## Liitteen ylätunniste
226
+
227
+ Ylätunnisteessa näkyy liitteen numero / liitteen sivu. Jos liitteessä yksi
228
+ olisi kaksi sivua, ensimmäisellä sivulla lukisi "Liite 1 / 1" ja toisella
229
+ sivulla "Liite 1 / 2". Esimerkin liitteessä on vain yksi sivu. Liite voi olla
230
+ vaakasuuntainen tai suurempi kuin A4-kokoinen.
231
+
232
+
233
+ _Tekijät: Taija Karppinen, Lea Mustonen, Katja Ruunaniemi, Sanna Tapiola_
234
+ [Alkuperäinen linkki](https://app.widgets.thinglink.com/accessibility/1503007817408184323)
readme_images/helpWithThesis2.png ADDED
requirements.txt ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ torch --index-url https://download.pytorch.org/whl/cpu
2
+ torchvision --index-url https://download.pytorch.org/whl/cpu
3
+ torchaudio --index-url https://download.pytorch.org/whl/cpu
4
+ faiss-cpu
5
+ transformers
6
+ accelerate
7
+ bitsandbytes
8
+ sentence-transformers
9
+ langchain
10
+ langchain-community
11
+ langchain-huggingface
12
+ pypdf
13
+ bs4
14
+ lxml
15
+ nltk
16
+ unstructured[md]
17
+ gradio
vector_store.py ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from langchain_community.document_loaders import TextLoader, PyPDFLoader
2
+ from langchain_community.document_loaders import BSHTMLLoader, UnstructuredMarkdownLoader
3
+ from langchain.text_splitter import RecursiveCharacterTextSplitter
4
+ from langchain_community.vectorstores import FAISS, VectorStore
5
+ from langchain_huggingface import HuggingFaceEmbeddings
6
+ from langchain_core.documents import Document
7
+ from pypdf.errors import PyPdfError
8
+ # stdlib
9
+ from glob import glob
10
+ import pathlib
11
+
12
+
13
+ async def load_text(file_path: str) -> list[Document] | None:
14
+ """Loads text documents (.txt) asynchronously from a passed file_path."""
15
+ assert file_path != ""
16
+ assert pathlib.Path(file_path).suffix == ".txt"
17
+
18
+ try:
19
+ loader = TextLoader(file_path)
20
+ return await loader.aload()
21
+ except UnicodeError or RuntimeError as err:
22
+ print(f"could not load file: {file_path}")
23
+ print(f"error: {err}")
24
+
25
+
26
+ # https://python.langchain.com/docs/how_to/document_loader_markdown/
27
+ async def load_markdown(file_path: str) -> list[Document] | None:
28
+ """Loads markdown files asynchronously from a passed file_path."""
29
+ assert file_path != ""
30
+ assert pathlib.Path(file_path).suffix == ".md"
31
+
32
+ try:
33
+ # use the mode elements to keep metadata about if the information is
34
+ # a paragraph, link or a heading for example
35
+ loader = UnstructuredMarkdownLoader(file_path, mode="elements")
36
+ return await loader.aload()
37
+ except UnicodeError or RuntimeError as err:
38
+ print(f"could not load file: {file_path}")
39
+ print(f"error: {err}")
40
+
41
+
42
+ # https://python.langchain.com/docs/how_to/document_loader_pdf/
43
+ async def load_pdf(file_path: str) -> list[Document] | None:
44
+ """Loads pdf documents (.pdf) asynchronously from a passed file_path."""
45
+ assert file_path != ""
46
+ assert pathlib.Path(file_path).suffix == ".pdf"
47
+
48
+ loader = PyPDFLoader(file_path)
49
+ try:
50
+ return await loader.aload()
51
+ except PyPdfError as err:
52
+ print(f"could not read file: {file_path}")
53
+ print(f"error: {err}")
54
+
55
+
56
+ async def load_html(file_path: str) -> list[Document]:
57
+ """Loads html documents (.html) asynchronously from a passed file_path."""
58
+ assert file_path != ""
59
+ assert pathlib.Path(file_path).suffix == ".html" or ".htm"
60
+
61
+ loader = BSHTMLLoader(file_path)
62
+ return await loader.aload()
63
+
64
+
65
+ # hold all of the loader functions for easy 0(1) fetching
66
+ LOADER_MAP = {
67
+ ".pdf": load_pdf,
68
+ ".html": load_html,
69
+ ".htm": load_html,
70
+ ".txt": load_text,
71
+ ".md": load_markdown,
72
+ }
73
+
74
+
75
+ # https://python.langchain.com/v0.1/docs/modules/data_connection/retrievers/vectorstore/
76
+ async def get_document_database(
77
+ data_folder="learning_material/*/*/*",
78
+ embedding_model="BAAI/bge-base-en-v1.5",
79
+ chunk_size=1028, chunk_overlap=0,
80
+ ) -> VectorStore:
81
+
82
+ # get all the filepaths of the learning materials
83
+ files = glob(data_folder)
84
+
85
+ all_docs = []
86
+ for file_path in files:
87
+ extension = pathlib.Path(file_path).suffix
88
+ if not extension:
89
+ print(f"{file_path} is a folder, skipping")
90
+ continue
91
+
92
+ load_fn = LOADER_MAP.get(extension)
93
+ if not load_fn:
94
+ print(f"no document loader for file extension '{extension}'")
95
+ print(f"file {file_path} will be skipped")
96
+ continue
97
+
98
+ # load the document with a filetype specific loader
99
+ result_documents = await load_fn(file_path)
100
+
101
+ if not result_documents:
102
+ print(f"file {file_path} does not include any content, skipping")
103
+ continue
104
+
105
+ all_docs.extend(result_documents)
106
+
107
+ splitter = RecursiveCharacterTextSplitter(
108
+ chunk_size=chunk_size,
109
+ chunk_overlap=chunk_overlap
110
+ )
111
+
112
+ chunked_docs = splitter.split_documents(all_docs)
113
+
114
+ return await FAISS.afrom_documents(
115
+ chunked_docs,
116
+ HuggingFaceEmbeddings(model_name=embedding_model)
117
+ )