import os, json, torch from torch.utils.data import Dataset from typing importDict, Optional, List from transformers import AutoModelForCausalLM, AutoTokenizer
What is the capital of France? The capital of France is Paris. Paris is a beautiful city known for its art, fashion, food, and culture. It is also home to many famous landmarks such as the Eiffel Tower, Notre-Dame Cathedral, and the Louvre Museum
chat 格式生成:
1 2 3 4 5 6
<|im_start|>system You are a helpful assistant.<|im_end|> <|im_start|>user What is the capital of France?<|im_end|> <|im_start|>assistant The capital of France is Paris.<|im_end|>
DatasetDict({ train: Dataset({ features: ['Context', 'Response'], num_rows: 3512 }) }) { "Context": "I'm going through some things with my feelings and myself. I barely sleep and I do nothing but think about how I'm worthless and how I shouldn't be here.\n I've never tried or contemplated suicide. I've always wanted to fix my issues, but I never get around to it.\n How can I change my feeling of being worthless to everyone?", "Response": "If everyone thinks you're worthless, then maybe you need to find new people to hang out with.Seriously, the social context in which a person lives is a big influence in self-esteem.Otherwise, you can go round and round trying to understand why you're not worthless, then go back to the same crowd and be knocked down again.There are many inspirational messages you can find in social media. Maybe read some of the ones which state that no person is worthless, and that everyone has a good purpose to their life.Also, since our culture is so saturated with the belief that if someone doesn't feel good about themselves that this is somehow terrible.Bad feelings are part of living. They are the motivation to remove ourselves from situations and relationships which do us more harm than good.Bad feelings do feel terrible. Your feeling of worthlessness may be good in the sense of motivating you to find out that you are much better than your feelings today." }
defprocess_into_chat_format(example): messages = [] messages.append({ "role": "system", "content": "You are a mental health counselor to help those who are suffering from a number of disorders including anxiety or depression.." }) messages.append({ "role": "user", "content": example["Context"].replace("\xa0", " ") }) messages.append({ "role": "assistant", "content": example["Response"].replace("\xa0", " ") }) return {"conversations": messages}
DatasetDict({ train: Dataset({ features: ['conversations'], num_rows: 3160 }) test: Dataset({ features: ['conversations'], num_rows: 352 }) }) { "conversations": [ { "content": "You are a mental health counselor to help those who are suffering from a number of disorders including anxiety or depression..", "role": "system" }, { "content": "I just took a job that requires me to travel far away from home. My family and I really need this job.\n People keep telling me I have \"anxiety\" and I'm terrified of having an anxiety attack on the road. This is all new to me. What can I do?", "role": "user" }, { "content": "It is ok to have anxiety. Please don't be anxious about being anxious.If you feel anxiety coming over you, then pull off the road to a safe place. Concentrate on centering yourself and to breath slowly. Take some sips of water. Sit still. The anxiety should pass in about twenty minutes.If it does not pass, then continue calming yourself until you feel safe enough to drive to your hotel. You can always explain to your supervisor that you were taking care of a medical problem, because anxiety is a medical problem.", "role": "assistant" } ] }
assertlen(input_ids) == len(labels), "Input IDs and labels must have the same length." # 截断 input_ids = input_ids[:max_length] labels = labels[:max_length] attention_mask = [1] * len(input_ids)
defdecode_labels(labels: List[int], tokenizer: AutoTokenizer) -> str: # 将 labels 中连续的非 -100 段分别 decode, 并用特殊分隔符拼接 segments = [] current = [] for t in labels: if t != -100: current.append(t) else: if current: segments.append(tokenizer.decode(current, skip_special_tokens=False)) current = [] if current: segments.append(tokenizer.decode(current, skip_special_tokens=False)) return segments
messages = [ {"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": "What is the capital of France?"}, {"role": "assistant", "content": "The capital of France is Paris."}, {"role": "user", "content": "What is the capital of Germany?"}, {"role": "assistant", "content": "The capital of Germany is Berlin."} ]
<|im_start|>system You are a helpful assistant.<|im_end|> <|im_start|>user What is the capital of France?<|im_end|> <|im_start|>assistant The capital of France is Paris.<|im_end|> <|im_start|>user What is the capital of Germany?<|im_end|> <|im_start|>assistant The capital of Germany is Berlin.<|im_end|>
Decoded input:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
Decoded input: <|im_start|>system You are a helpful assistant.<|im_end|> <|im_start|>user What is the capital of France?<|im_end|> <|im_start|>assistant The capital of France is Paris.<|im_end|> <|im_start|>user What is the capital of Germany?<|im_end|> <|im_start|>assistant The capital of Germany is Berlin.<|im_end|>
Decoded labels: ['The capital of France is Paris.<|im_end|>', 'The capital of Germany is Berlin.<|im_end|>']
Decoded labels: [‘The capital of France is Paris.<|im_end|>’, ‘The capital of Germany is Berlin.<|im_end|>’]
labels中非-100的只有
1 2 3 4 5 6 7 8 9 10 11 12
defwrapped_preprocess(example, tokenizer, max_length=2048): # batched=True: example["conversations"] is a list of conversations conversations_list = example["conversations"] results = preprocess_openai_messages_qwen_format(example["conversations"], tokenizer, max_length) return results
Instead of fighting about trust, is it possible for you and your wife to talk with other about areas which upset each of you?Whenever feelings are hurt, knowing what exactly is problematic and being heard and understood by the partner, goes a long way to building trust.These type of discussions are hard to have, and especially for the first time. A lot of emotions arise and often people lose their conversation focus from this.If you and your wife have a tough time opening up to each other, consider scheduling time with a couples therapist.Just by each of you committing time to invest in the relationship will show faith in the relationship, and this may contribute to restoring trust.
微调前
It sounds like you’re experiencing significant distress related to feelings of betrayal and loss of trust, which can be deeply painful and challenging to navigate. It’s important to address these emotions and the situation with care and consideration for both your own emotional well-being and that of your wife.
Here are some steps you might consider:
Communication: Have an open, honest conversation with your wife about how you feel. It’s crucial to express your concerns without placing blame. Use “I” statements to avoid making her defensive. For example, say something like, “I’ve been feeling really hurt by the recent changes in our relationship dynamics.”
Listening: Allow your wife to express her side of the story. Sometimes, people act out of fear or insecurity. Listening can provide you with insights into why she may have acted as she did and show her that you respect her perspective.
Seek Support: Consider speaking with a therapist or counselor who can help facilitate communication between you and your wife. They can offer strategies for rebuilding trust and understanding.
Establish Boundaries: Set clear boundaries regarding privacy and communication with friends and romantic partners. This can help prevent similar situations from arising in the future.
Self-Care: Engage in activities that promote your mental and emotional health. This could include exercise, meditation, or hobbies that bring you joy and relaxation.
Professional Help: If the situation feels overwhelming, professional guidance can be invaluable. A psychologist or psychiatrist can provide tools and techniques to help manage your anxiety and depression, which are common responses to betrayal and loss of trust.
Time: Give yourself and your wife time to heal. Healing takes time, and it’s essential not to rush this process.
Remember, the goal is to strengthen your relationship, not just to survive the current crisis. Trust can be rebuilt over time with patience, honesty, and commitment from both of you.
How does this resonate with you, and what specific areas do you need more assistance with?<|im_end|>
微调后
It sounds like you are in the middle of a “trust gap” between your spouse and yourself. You both are in different places emotionally regarding the issue of trust. It is a good idea for you to start by talking with your wife about what you have experienced and how it has affected you. She may not be aware of your feelings and concerns. You may also want to discuss your thoughts and feelings with someone else outside of your marriage, such as a trusted family member, friend, or therapist. Having an objective listener can help you sort through your feelings and thoughts regarding this situation. <|im_end|>